Exemplo n.º 1
0
 print '<td align="right">' . $langs->trans('PaymentAmount') . '</td>';
 print '<td align="right">&nbsp;</td>';
 print "</tr>\n";
 $var = True;
 $total = 0;
 $totalrecu = 0;
 $totalrecucreditnote = 0;
 $totalrecudeposits = 0;
 while ($i < $num) {
     $objp = $db->fetch_object($resql);
     $var = !$var;
     $invoice = new Facture($db);
     $invoice->fetch($objp->facid);
     $paiement = $invoice->getSommePaiement();
     $creditnotes = $invoice->getSumCreditNotesUsed();
     $deposits = $invoice->getSumDepositsUsed();
     $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
     $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
     print '<tr ' . $bc[$var] . '>';
     print '<td>';
     print $invoice->getNomUrl(1, '');
     print "</td>\n";
     // Date
     print '<td align="center">' . dol_print_date($db->jdate($objp->df), 'day') . "</td>\n";
     // Prix
     print '<td align="right">' . price($objp->total_ttc) . '</td>';
     // Recu
     print '<td align="right">' . price($paiement);
     if ($creditnotes) {
         print '+' . price($creditnotes);
     }
 /**
  *	Show total to pay
  *
  *	@param	PDF			$pdf           Object PDF
  *	@param  Facture		$object         Object invoice
  *	@param  int			$deja_regle     Montant deja regle
  *	@param	int			$posy			Position depart
  *	@param	Translate	$outputlangs	Objet langs
  *	@return int							Position pour suite
  */
 function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
 {
     global $conf, $mysoc;
     $sign = 1;
     if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
         $sign = -1;
     }
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     $tab2_top = $posy;
     $tab2_hl = 4;
     $pdf->SetFont('', '', $default_font_size - 1);
     // Tableau total
     $col1x = 120;
     $col2x = 170;
     if ($this->page_largeur < 210) {
         $col2x -= 20;
     }
     $largcol2 = $this->page_largeur - $this->marge_droite - $col2x;
     $useborder = 0;
     $index = 0;
     // Total HT
     $pdf->SetFillColor(255, 255, 255);
     $pdf->SetXY($col1x, $tab2_top + 0);
     $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
     $total_ht = $conf->multicurrency->enabled && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht;
     $pdf->SetXY($col2x, $tab2_top + 0);
     $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1);
     // Show VAT by rates and total
     $pdf->SetFillColor(248, 248, 248);
     $this->atleastoneratenotnull = 0;
     if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
         $tvaisnull = !empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000']) ? true : false;
         if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_ISNULL) && $tvaisnull) {
             // Nothing to do
         } else {
             //Local tax 1 before VAT
             //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
             //{
             foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
                 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
                     continue;
                 }
                 foreach ($localtax_rate as $tvakey => $tvaval) {
                     if ($tvakey != 0) {
                         //$this->atleastoneratenotnull++;
                         $index++;
                         $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
                         $tvacompl = '';
                         if (preg_match('/\\*/', $tvakey)) {
                             $tvakey = str_replace('*', '', $tvakey);
                             $tvacompl = " (" . $outputlangs->transnoentities("NonPercuRecuperable") . ")";
                         }
                         $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code) . ' ';
                         $totalvat .= vatrate(abs($tvakey), 1) . $tvacompl;
                         $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
                         $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
                         $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
                     }
                 }
             }
             //}
             //Local tax 2 before VAT
             //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
             //{
             foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
                 if (in_array((string) $localtax_type, array('1', '3', '5'))) {
                     continue;
                 }
                 foreach ($localtax_rate as $tvakey => $tvaval) {
                     if ($tvakey != 0) {
                         //$this->atleastoneratenotnull++;
                         $index++;
                         $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
                         $tvacompl = '';
                         if (preg_match('/\\*/', $tvakey)) {
                             $tvakey = str_replace('*', '', $tvakey);
                             $tvacompl = " (" . $outputlangs->transnoentities("NonPercuRecuperable") . ")";
                         }
                         $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code) . ' ';
                         $totalvat .= vatrate(abs($tvakey), 1) . $tvacompl;
                         $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
                         $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
                         $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
                     }
                 }
             }
             //}
             // VAT
             foreach ($this->tva as $tvakey => $tvaval) {
                 if ($tvakey > 0) {
                     $this->atleastoneratenotnull++;
                     $index++;
                     $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
                     $tvacompl = '';
                     if (preg_match('/\\*/', $tvakey)) {
                         $tvakey = str_replace('*', '', $tvakey);
                         $tvacompl = " (" . $outputlangs->transnoentities("NonPercuRecuperable") . ")";
                     }
                     $totalvat = $outputlangs->transnoentities("TotalVAT") . ' ';
                     $totalvat .= vatrate($tvakey, 1) . $tvacompl;
                     $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
                     $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
                     $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
                 }
             }
             //Local tax 1 after VAT
             //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
             //{
             foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
                 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
                     continue;
                 }
                 foreach ($localtax_rate as $tvakey => $tvaval) {
                     if ($tvakey != 0) {
                         //$this->atleastoneratenotnull++;
                         $index++;
                         $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
                         $tvacompl = '';
                         if (preg_match('/\\*/', $tvakey)) {
                             $tvakey = str_replace('*', '', $tvakey);
                             $tvacompl = " (" . $outputlangs->transnoentities("NonPercuRecuperable") . ")";
                         }
                         $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code) . ' ';
                         $totalvat .= vatrate(abs($tvakey), 1) . $tvacompl;
                         $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
                         $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
                         $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
                     }
                 }
             }
             //}
             //Local tax 2 after VAT
             //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
             //{
             foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
                 if (in_array((string) $localtax_type, array('2', '4', '6'))) {
                     continue;
                 }
                 foreach ($localtax_rate as $tvakey => $tvaval) {
                     // retrieve global local tax
                     if ($tvakey != 0) {
                         //$this->atleastoneratenotnull++;
                         $index++;
                         $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
                         $tvacompl = '';
                         if (preg_match('/\\*/', $tvakey)) {
                             $tvakey = str_replace('*', '', $tvakey);
                             $tvacompl = " (" . $outputlangs->transnoentities("NonPercuRecuperable") . ")";
                         }
                         $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code) . ' ';
                         $totalvat .= vatrate(abs($tvakey), 1) . $tvacompl;
                         $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
                         $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
                         $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
                     }
                 }
                 //}
             }
             // Revenue stamp
             if (price2num($object->revenuestamp) != 0) {
                 $index++;
                 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
                 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1);
                 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
                 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1);
             }
             // Total TTC
             $index++;
             $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
             $pdf->SetTextColor(0, 0, 60);
             $pdf->SetFillColor(224, 224, 224);
             $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
             $total_ttc = $conf->multicurrency->enabled && $object->multiccurency_tx != 1 ? $object->multicurrency_total_ttc : $object->total_ttc;
             $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
             $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
         }
     }
     $pdf->SetTextColor(0, 0, 0);
     $creditnoteamount = $object->getSumCreditNotesUsed();
     $depositsamount = $object->getSumDepositsUsed();
     //print "x".$creditnoteamount."-".$depositsamount;exit;
     $resteapayer = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
     if ($object->paye) {
         $resteapayer = 0;
     }
     if ($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) {
         // Already paid + Deposits
         $index++;
         $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
         $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("Paid"), 0, 'L', 0);
         $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
         $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount, 0, $outputlangs), 0, 'R', 0);
         // Credit note
         if ($creditnoteamount) {
             $index++;
             $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
             $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0);
             $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
             $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount, 0, $outputlangs), 0, 'R', 0);
         }
         // Escompte
         if ($object->close_code == Facture::CLOSECODE_DISCOUNTVAT) {
             $index++;
             $pdf->SetFillColor(255, 255, 255);
             $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
             $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
             $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
             $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 0, $outputlangs), $useborder, 'R', 1);
             $resteapayer = 0;
         }
         $index++;
         $pdf->SetTextColor(0, 0, 60);
         $pdf->SetFillColor(224, 224, 224);
         $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
         $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
         $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
         $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->SetTextColor(0, 0, 0);
     }
     $index++;
     return $tab2_top + $tab2_hl * $index;
 }
Exemplo n.º 3
0
 /**
  *    Create payment of invoices into database.
  *    Use this->amounts to have list of invoices for the payment.
  *    For payment of a customer invoice, amounts are postive, for payment of credit note, amounts are negative
  *
  *    @param	User	$user                	Object user
  *    @param    int		$closepaidinvoices   	1=Also close payed invoices to paid, 0=Do nothing more
  *    @return   int                 			id of created payment, < 0 if error
  */
 function create($user, $closepaidinvoices = 0)
 {
     global $conf, $langs;
     $error = 0;
     $now = dol_now();
     // Clean parameters
     $totalamount = 0;
     $atleastonepaymentnotnull = 0;
     foreach ($this->amounts as $key => $value) {
         $newvalue = price2num($value, 'MT');
         $this->amounts[$key] = $newvalue;
         $totalamount += $newvalue;
         if (!empty($newvalue)) {
             $atleastonepaymentnotnull++;
         }
     }
     $totalamount = price2num($totalamount);
     // Check parameters
     if (empty($totalamount) && empty($atleastonepaymentnotnull)) {
         $this->error = 'TotalAmountEmpty';
         return -1;
     }
     $this->db->begin();
     $ref = $this->getNextNumRef('');
     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "paiement (entity, ref, datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)";
     $sql .= " VALUES (" . $conf->entity . ", '" . $ref . "', '" . $this->db->idate($now) . "', '" . $this->db->idate($this->datepaye) . "', '" . $totalamount . "', " . $this->paiementid . ", '" . $this->num_paiement . "', '" . $this->db->escape($this->note) . "', " . $user->id . ")";
     dol_syslog(get_class($this) . "::Create insert paiement", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . 'paiement');
         // Insert links amount / invoices
         foreach ($this->amounts as $key => $amount) {
             $facid = $key;
             if (is_numeric($amount) && $amount != 0) {
                 $amount = price2num($amount);
                 $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'paiement_facture (fk_facture, fk_paiement, amount)';
                 $sql .= ' VALUES (' . $facid . ', ' . $this->id . ', \'' . $amount . '\')';
                 dol_syslog(get_class($this) . '::Create Amount line ' . $key . ' insert paiement_facture', LOG_DEBUG);
                 $resql = $this->db->query($sql);
                 if ($resql) {
                     // If we want to closed payed invoices
                     if ($closepaidinvoices) {
                         $invoice = new Facture($this->db);
                         $invoice->fetch($facid);
                         $paiement = $invoice->getSommePaiement();
                         $creditnotes = $invoice->getSumCreditNotesUsed();
                         $deposits = $invoice->getSumDepositsUsed();
                         $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
                         $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
                         //var_dump($invoice->total_ttc.' - '.$paiement.' -'.$creditnotes.' - '.$deposits.' - '.$remaintopay);exit;
                         // If there is withdrawals request to do and not done yet, we wait before closing.
                         $mustwait = 0;
                         $listofpayments = $invoice->getListOfPayments();
                         foreach ($listofpayments as $paym) {
                             // This payment might be this one or a previous one
                             if ($paym['type'] == 'PRE') {
                                 if (!empty($conf->prelevement->enabled)) {
                                     // TODO Check if this payment has a withdraw request
                                     // if not, $mustwait++;      // This will disable automatic close on invoice to allow to process
                                 }
                             }
                         }
                         //Invoice types that are eligible for changing status to paid
                         $affected_types = array(Facture::TYPE_STANDARD, Facture::TYPE_REPLACEMENT, Facture::TYPE_CREDIT_NOTE, Facture::TYPE_DEPOSIT, Facture::TYPE_SITUATION);
                         if (!in_array($invoice->type, $affected_types)) {
                             dol_syslog("Invoice " . $facid . " is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
                         } else {
                             if ($remaintopay) {
                                 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
                             } else {
                                 if ($mustwait) {
                                     dol_syslog("There is " . $mustwait . " differed payment to process, we do nothing more.");
                                 } else {
                                     $result = $invoice->set_paid($user, '', '');
                                     if ($result < 0) {
                                         $this->error = $invoice->error;
                                         $error++;
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     $this->error = $this->db->lasterror();
                     $error++;
                 }
             } else {
                 dol_syslog(get_class($this) . '::Create Amount line ' . $key . ' not a number. We discard it.');
             }
         }
         if (!$error) {
             // Appel des triggers
             $result = $this->call_trigger('PAYMENT_CUSTOMER_CREATE', $user);
             if ($result < 0) {
                 $error++;
             }
             // Fin appel triggers
         }
     } else {
         $this->error = $this->db->lasterror();
         $error++;
     }
     if (!$error) {
         $this->amount = $totalamount;
         $this->total = $totalamount;
         // deprecated
         $this->db->commit();
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
Exemplo n.º 4
0
             $line->total_localtax1 = -$line->total_localtax1;
             $line->total_localtax2 = -$line->total_localtax2;
             $line->insert();
             $object->lines[] = $line;
             // insert new line in current object
         }
         $object->update_price(1);
     }
 }
 if (GETPOST('invoiceAvoirWithPaymentRestAmount', 'int') == 1 && $id > 0) {
     $facture_source = new Facture($db);
     // fetch origin object if not previously defined
     if ($facture_source->fetch($object->fk_facture_source) > 0) {
         $totalpaye = $facture_source->getSommePaiement();
         $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
         $totaldeposits = $facture_source->getSumDepositsUsed();
         $remain_to_pay = abs($facture_source->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits);
         $object->addline($langs->trans('invoiceAvoirLineWithPaymentRestAmount'), $remain_to_pay, 1, 0, 0, 0, 0, 0, '', '', 'TTC');
     }
 }
 // Add predefined lines
 /*
 	             TODO delete
 	             for($i = 1; $i <= $NBLINES; $i ++) {
 					if ($_POST['idprod' . $i]) {
 						$product = new Product($db);
 						$product->fetch($_POST['idprod' . $i]);
 						$startday = dol_mktime(12, 0, 0, $_POST['date_start' . $i . 'month'], $_POST['date_start' . $i . 'day'], $_POST['date_start' . $i . 'year']);
 						$endday = dol_mktime(12, 0, 0, $_POST['date_end' . $i . 'month'], $_POST['date_end' . $i . 'day'], $_POST['date_end' . $i . 'year']);
 						$result = $object->addline($product->description, $product->price, $_POST['qty' . $i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST['idprod' . $i], $_POST['remise_percent' . $i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
 					}
Exemplo n.º 5
0
 print '<td>';
 $form->form_modes_reglement($_SERVER['PHP_SELF'], $objp->fk_mode_reglement, 'none');
 print '</td>';
 print '<td align="right">' . price($objp->total_ht) . '</td>';
 print '<td align="right">' . price($objp->total_tva);
 $tx1 = price2num($objp->localtax1);
 $tx2 = price2num($objp->localtax2);
 $revenuestamp = price2num($objp->revenuestamp);
 if (!empty($tx1) || !empty($tx2) || !empty($revenuestamp)) {
     print '+' . price($tx1 + $tx2 + $revenuestamp);
 }
 print '</td>';
 print '<td align="right">' . price($objp->total_ttc) . '</td>';
 print '<td align="right">';
 $cn = $facturestatic->getSumCreditNotesUsed();
 $dep = $facturestatic->getSumDepositsUsed();
 print price($objp->am + $cn + $dep);
 print '</td>';
 // Remain to receive
 print '<td align="right">' . price($objp->total_ttc - $objp->am - $cn - $dep) . '</td>';
 // Status of invoice
 print '<td align="right" class="nowrap">';
 print $facturestatic->LibStatut($objp->paye, $objp->fk_statut, 5, $objp->am);
 print '</td>';
 if (empty($mode)) {
     // Checkbox to merge
     print '<td align="center">';
     if (!empty($formfile->numoffiles)) {
         print '<input id="cb' . $objp->facid . '" class="flat checkformerge" type="checkbox" name="toGenerate[]" value="' . $objp->facnumber . '">';
     } else {
         print '&nbsp;';
Exemplo n.º 6
0
/*                                                                             */
/* *************************************************************************** */

if ($_REQUEST["facid"] > 0 || $_REQUEST["ref"])
{
    $fac = new Facture($db);
    if ($fac->fetch($_REQUEST["facid"], $_REQUEST["ref"]) > 0)
    {
        if ($mesg) print $mesg.'<br>';

        $soc = new Societe($db, $fac->socid);
        $soc->fetch($fac->socid);

        $totalpaye  = $fac->getSommePaiement();
        $totalcreditnotes = $fac->getSumCreditNotesUsed();
        $totaldeposits = $fac->getSumDepositsUsed();
        //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;

        // We can also use bcadd to avoid pb with floating points
        // For example print 239.2 - 229.3 - 9.9; does not return 0.
        //$resteapayer=bcadd($fac->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
        //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
        $resteapayer = price2num($fac->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');

        if ($fac->paye) $resteapayer=0;
        $resteapayeraffiche=$resteapayer;

        $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL');
        $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL');
        $absolute_discount=price2num($absolute_discount,'MT');
        $absolute_creditnote=price2num($absolute_creditnote,'MT');
Exemplo n.º 7
0
    /**
     *  Return amount of bill not paid
     *
     *  @return		int				Amount in debt for thirdparty
     */
    function get_OutstandingBill()
    {
		/* Accurate value of remain to pay is to sum remaintopay for each invoice
		$paiement = $invoice->getSommePaiement();
		$creditnotes=$invoice->getSumCreditNotesUsed();
		$deposits=$invoice->getSumDepositsUsed();
		$alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
		$remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
		*/
		$sql  = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f";
		$sql .= " WHERE fk_soc = ". $this->id;
		$sql .= " AND paye = 0";
		$sql .= " AND fk_statut <> 0";	// Not a draft
		//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
		$sql .= " AND fk_statut <> 3";		// Not abandonned
		$sql .= " AND fk_statut <> 2";		// Not clasified as paid

		dol_syslog("get_OutstandingBill", LOG_DEBUG);
		$resql=$this->db->query($sql);
		if ($resql)
		{
			$outstandingBill = 0;
			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
			$facturestatic=new Facture($this->db);
			while($obj=$this->db->fetch_object($resql)) {
				$facturestatic->id=$obj->rowid;
				$paiement = $facturestatic->getSommePaiement();
				$creditnotes = $facturestatic->getSumCreditNotesUsed();
				$deposits = $facturestatic->getSumDepositsUsed();

				$outstandingBill+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
   			}
   			return $outstandingBill;
		}
		else
			return 0;
	}
Exemplo n.º 8
0
 /**
  *	Set withdrawal to credited status
  *
  *	@param	User		$user		id of user
  *	@param 	int	$date		date of action
  *	@return	int						>0 if OK, <0 if KO
  */
 function set_infocredit($user, $date)
 {
     global $conf, $langs;
     $error = 0;
     if ($this->_fetched == 1) {
         if ($date >= $this->date_trans) {
             if ($this->db->begin()) {
                 $sql = " UPDATE " . MAIN_DB_PREFIX . "prelevement_bons ";
                 $sql .= " SET fk_user_credit = " . $user->id;
                 $sql .= ", statut = 2";
                 $sql .= ", date_credit = '" . $this->db->idate($date) . "'";
                 $sql .= " WHERE rowid=" . $this->id;
                 $sql .= " AND entity = " . $conf->entity;
                 $sql .= " AND statut = 1";
                 if ($this->db->query($sql)) {
                     $langs->load('withdrawals');
                     $subject = $langs->trans("InfoCreditSubject", $this->ref);
                     $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date, 'dayhour'));
                     //Add payment of withdrawal into bank
                     $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
                     $facs = array();
                     $amounts = array();
                     $facs = $this->getListInvoices(1);
                     $num = count($facs);
                     for ($i = 0; $i < $num; $i++) {
                         $fac = new Facture($this->db);
                         $fac->fetch($facs[$i][0]);
                         $amounts[$fac->id] = $facs[$i][1];
                         $totalpaye = $fac->getSommePaiement();
                         $totalcreditnotes = $fac->getSumCreditNotesUsed();
                         $totaldeposits = $fac->getSumDepositsUsed();
                         $alreadypayed = $totalpaye + $totalcreditnotes + $totaldeposits;
                         if ($alreadypayed + $facs[$i][1] >= $fac->total_ttc) {
                             $result = $fac->set_paid($user);
                         }
                     }
                     $paiement = new Paiement($this->db);
                     $paiement->datepaye = $date;
                     $paiement->amounts = $amounts;
                     $paiement->paiementid = 3;
                     //
                     $paiement->num_paiement = $this->ref;
                     $paiement_id = $paiement->create($user);
                     if ($paiement_id < 0) {
                         dol_syslog(get_class($this) . "::set_credite AddPayment Error");
                         $error++;
                     } else {
                         $result = $paiement->addPaymentToBank($user, 'payment', '(WithdrawalPayment)', $bankaccount, '', '');
                         if ($result < 0) {
                             dol_syslog(get_class($this) . "::set_credite AddPaymentToBank Error");
                             $error++;
                         }
                     }
                     // Update prelevement line
                     // TODO: Translate to ligneprelevement.class.php
                     $sql = " UPDATE " . MAIN_DB_PREFIX . "prelevement_lignes";
                     $sql .= " SET statut = 2";
                     $sql .= " WHERE fk_prelevement_bons = " . $this->id;
                     if (!$this->db->query($sql)) {
                         dol_syslog(get_class($this) . "::set_credite Update lines Error");
                         $error++;
                     }
                 } else {
                     dol_syslog(get_class($this) . "::set_infocredit Update Bons Error");
                     $error++;
                 }
                 /*
                  * End of procedure
                  */
                 if ($error == 0) {
                     $this->db->commit();
                     return 0;
                 } else {
                     $this->db->rollback();
                     dol_syslog("bon-prelevment::set_infocredit ROLLBACK ");
                     return -1;
                 }
             } else {
                 dol_syslog(get_class($this) . "::set_infocredit 1025 Open SQL transaction impossible ");
                 return -1025;
             }
         } else {
             dol_syslog("bon-prelevment::set_infocredit 1027 Date de credit < Date de trans ");
             return -1027;
         }
     } else {
         return -1026;
     }
 }
Exemplo n.º 9
0
}
/*
 * View
 */
$now = dol_now();
llxHeader('', $langs->trans("Bill"));
$form = new Form($db);
/* *************************************************************************** */
/*                                                                             */
/* Mode fiche                                                                  */
/*                                                                             */
/* *************************************************************************** */
if ($object->id > 0) {
    $totalpaye = $object->getSommePaiement();
    $totalcreditnotes = $object->getSumCreditNotesUsed();
    $totaldeposits = $object->getSumDepositsUsed();
    //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits;
    // We can also use bcadd to avoid pb with floating points
    // For example print 239.2 - 229.3 - 9.9; does not return 0.
    //$resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
    //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
    $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
    if ($object->paye) {
        $resteapayer = 0;
    }
    $resteapayeraffiche = $resteapayer;
    $absolute_discount = $object->thirdparty->getAvailableDiscounts('', 'fk_facture_source IS NULL');
    $absolute_creditnote = $object->thirdparty->getAvailableDiscounts('', 'fk_facture_source IS NOT NULL');
    $absolute_discount = price2num($absolute_discount, 'MT');
    $absolute_creditnote = price2num($absolute_creditnote, 'MT');
    $author = new User($db);
Exemplo n.º 10
0
 /**
  *	Show total to pay
  *
  *	@param	PDF			&$pdf           Object PDF
  *	@param  Facture		$object         Object invoice
  *	@param  int			$deja_regle     Montant deja regle
  *	@param	int			$posy			Position depart
  *	@param	Translate	$outputlangs	Objet langs
  *	@return int							Position pour suite
  */
 function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
 {
     global $conf, $langs;
     $sign = 1;
     if ($object->type == 2 && !empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) {
         $sign = -1;
     }
     $langs->load("main");
     $langs->load("bills");
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     $tab2_top = $this->marges['h'] + 202;
     $tab2_hl = 4;
     $pdf->SetFont('', '', $default_font_size - 1);
     // Tableau total
     $col1x = $this->marges['g'] + 110;
     $col2x = $this->marges['g'] + 164;
     $largcol2 = $this->page_largeur - $this->marge_droite - $col2x;
     $pdf->SetXY($this->marges['g'], $tab2_top + 0);
     $useborder = 0;
     $index = 0;
     // Total HT
     $pdf->SetXY($col1x, $tab2_top + 0);
     $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 0);
     $pdf->SetXY($col2x, $tab2_top + 0);
     $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($object->total_ht + $object->remise)), 0, 'R', 0);
     // Show VAT by rates and total
     $pdf->SetFillColor(248, 248, 248);
     $this->atleastoneratenotnull = 0;
     if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
         foreach ($this->tva as $tvakey => $tvaval) {
             if ($tvakey > 0) {
                 $this->atleastoneratenotnull++;
                 $index++;
                 $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
                 $tvacompl = '';
                 if (preg_match('/\\*/', $tvakey)) {
                     $tvakey = str_replace('*', '', $tvakey);
                     $tvacompl = " (" . $outputlangs->transnoentities("NonPercuRecuperable") . ")";
                 }
                 $totalvat = $outputlangs->transnoentities("TotalVAT") . ' ';
                 $totalvat .= vatrate($tvakey, 1) . $tvacompl;
                 $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
                 $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
                 $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $tvaval), 0, 'R', 1);
             }
         }
         if (!$this->atleastoneratenotnull) {
             $index++;
             $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
             $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
             $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
             $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_tva), 0, 'R', 1);
         }
     }
     // Total TTC
     if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
         $index++;
         $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
         $pdf->SetTextColor(22, 137, 210);
         $pdf->SetFont('', 'B', $default_font_size + 1);
         $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), 0, 'L', 0);
         $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
         $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_ttc), 0, 'R', 0);
         $pdf->SetTextColor(0, 0, 0);
     }
     $creditnoteamount = $object->getSumCreditNotesUsed();
     $depositsamount = $object->getSumDepositsUsed();
     $resteapayer = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
     if ($object->paye) {
         $resteapayer = 0;
     }
     if ($deja_regle > 0 || $creditnoteamount > 0 || $depositsamount > 0) {
         $pdf->SetFont('', '', $default_font_size);
         // Already paid + Deposits
         $index++;
         $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
         $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
         $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
         $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle + $depositsamount), 0, 'R', 0);
         // Credit note
         if ($creditnoteamount) {
             $index++;
             $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
             $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("CreditNotes"), 0, 'L', 0);
             $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
             $pdf->MultiCell($largcol2, $tab2_hl, price($creditnoteamount), 0, 'R', 0);
         }
         // Escompte
         if ($object->close_code == 'discount_vat') {
             $index++;
             $pdf->SetFillColor(255, 255, 255);
             $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
             $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOffered"), $useborder, 'L', 1);
             $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
             $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount), $useborder, 'R', 1);
             $resteapayer = 0;
         }
         $index++;
         $pdf->SetTextColor(0, 0, 60);
         $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
         $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), 0, 'L', 0);
         $pdf->SetFillColor(224, 224, 224);
         $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
         $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), 0, 'R', 0);
         // Fin
         $pdf->SetFont('', 'B', $default_font_size + 1);
         $pdf->SetTextColor(0, 0, 0);
     }
     $index++;
     return $tab2_top + $tab2_hl * $index;
 }
Exemplo n.º 11
0
	/**
	 *    Create payment of invoices into database.
	 *    Use this->amounts to have list of invoices for the payment
	 *    @param       user                object user
	 *    @param       closepaidinvoices   1=Also close payed invoices to paid, 0=Do nothing more
	 *    @return      int                 id of created payment, < 0 if error
	 */
	function create($user,$closepaidinvoices=0)
	{
		global $langs,$conf;

		$error = 0;

        $now=dol_now();

        // Clean parameters
        $totalamount = 0;
		foreach ($this->amounts as $key => $value)	// How payment is dispatch
		{
			$newvalue = price2num($value,'MT');
			$this->amounts[$key] = $newvalue;
			$totalamount += $newvalue;
		}
		$totalamount = price2num($totalamount);

		// Check parameters
        if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null


		$this->db->begin();

		$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)";
		$sql.= " VALUES ('".$this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$totalamount."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.")";

		dol_syslog(get_class($this)."::Create insert paiement sql=".$sql);
		$resql = $this->db->query($sql);
		if ($resql)
		{
			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');

			// Insert links amount / invoices
			foreach ($this->amounts as $key => $amount)
			{
				$facid = $key;
				if (is_numeric($amount) && $amount <> 0)
				{
					$amount = price2num($amount);
					$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount)';
					$sql .= ' VALUES ('.$facid.', '. $this->id.', \''.$amount.'\')';

					dol_syslog(get_class($this).'::Create Amount line '.$key.' insert paiement_facture sql='.$sql);
					$resql=$this->db->query($sql);
					if ($resql)
					{
						// If we want to closed payed invoices
					    if ($closepaidinvoices)
					    {
					        $invoice=new Facture($this->db);
					        $invoice->fetch($facid);
                            $paiement = $invoice->getSommePaiement();
                            $creditnotes=$invoice->getSumCreditNotesUsed();
                            $deposits=$invoice->getSumDepositsUsed();
                            $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
                            $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
                            // If there is withdrawals request to do and not done yet, we wait before closing.
                            $mustwait=0;
                            $listofpayments=$invoice->getListOfPayments();
                            foreach($listofpayments as $paym)
                            {
                                // This payment might be this one or a previous one
                                if ($paym['type']=='PRE')
                                {
                                    if ($conf->prelevement->enabled)
                                    {
                                        // TODO Check if this payment has a withdraw request
                                        // if not, $mustwait++;      // This will disable automatic close on invoice to allow to process
                                    }
                                }
                            }

                            if ($invoice->type != 0 && $invoice->type != 1) dol_syslog("Invoice ".$facid." is not a standard nor replacement invoice. We do nothing more.");
                            else if ($remaintopay) dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more.");
                            else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
                            else $result=$invoice->set_paid($user,'','');
					    }
					}
					else
					{
						$this->error=$this->db->lasterror();
						dol_syslog(get_class($this).'::Create insert paiement_facture error='.$this->error, LOG_ERR);
						$error++;
					}
				}
				else
				{
					dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
				}
			}

			if (! $error)
			{
				// Appel des triggers
				include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
				$interface=new Interfaces($this->db);
				$result=$interface->run_triggers('PAYMENT_CUSTOMER_CREATE',$this,$user,$langs,$conf);
				if ($result < 0) { $error++; $this->errors=$interface->errors; }
				// Fin appel triggers
			}
		}
		else
		{
			$this->error=$this->db->lasterror();
			dol_syslog(get_class($this).'::Create insert paiement error='.$this->error, LOG_ERR);
			$error++;
		}

		if (! $error)
		{
		    $this->amount=$totalamount;
		    $this->total=$totalamount;    // deprecated
			$this->db->commit();
			return $this->id;
		}
		else
		{
			$this->db->rollback();
			return -1;
		}
	}