Exemplo n.º 1
0
 print '<td align="right">' . $langs->trans('Received') . '</td>';
 print '<td align="right">' . $langs->trans('RemainderToPay') . '</td>';
 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) {
Exemplo n.º 2
0
         $societestatic->id = $obj->socid;
         $societestatic->name = $obj->name;
         $refcomp = $societestatic->getNomUrl(1, '', 24);
         $paiement = -1 * $facturefournstatic->getSommePaiement();
         // Payment already done
     }
 }
 if ($obj->family == 'invoice') {
     $facturestatic->ref = $obj->ref;
     $facturestatic->id = $obj->objid;
     $facturestatic->type = $obj->type;
     $ref = $facturestatic->getNomUrl(1, '');
     $societestatic->id = $obj->socid;
     $societestatic->name = $obj->name;
     $refcomp = $societestatic->getNomUrl(1, '', 24);
     $paiement = $facturestatic->getSommePaiement();
     // Payment already done
 }
 if ($obj->family == 'social_contribution') {
     $socialcontribstatic->ref = $obj->ref;
     $socialcontribstatic->id = $obj->objid;
     $socialcontribstatic->lib = $obj->type;
     $ref = $socialcontribstatic->getNomUrl(1, 24);
     $paiement = -1 * $socialcontribstatic->getSommePaiement();
     // Payment already done
 }
 $total_ttc = $obj->total_ttc;
 if ($paiement) {
     $total_ttc = $obj->total_ttc - $paiement;
 }
 $solde += $total_ttc;
Exemplo n.º 3
0
             $line->total_tva = -$line->total_tva;
             $line->total_ttc = -$line->total_ttc;
             $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']);
Exemplo n.º 4
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.º 5
0
    print '<input type="hidden" name="desc" value="' . $langs->trans("Order") . ' ' . $order->ref . '">' . "\n";
}
// Payment on customer invoice
if (GETPOST("source") == 'invoice' && $valid) {
    $found = true;
    $langs->load("bills");
    require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
    $invoice = new Facture($db);
    $result = $invoice->fetch('', $ref);
    if ($result < 0) {
        $mesg = $invoice->error;
        $error++;
    } else {
        $result = $invoice->fetch_thirdparty($invoice->socid);
    }
    $amount = price2num($invoice->total_ttc - $invoice->getSommePaiement());
    if (GETPOST("amount", 'int')) {
        $amount = GETPOST("amount", 'int');
    }
    $amount = price2num($amount);
    $fulltag = 'INV=' . $invoice->ref . '.CUS=' . $invoice->thirdparty->id;
    //$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," ");
    if (!empty($TAG)) {
        $tag = $TAG;
        $fulltag .= '.TAG=' . $TAG;
    }
    $fulltag = dol_string_unaccent($fulltag);
    // Creditor
    $var = !$var;
    print '<tr class="CTableRow' . ($var ? '1' : '2') . '"><td class="CTableRow' . ($var ? '1' : '2') . '">' . $langs->trans("Creditor");
    print '</td><td class="CTableRow' . ($var ? '1' : '2') . '"><b>' . $creditor . '</b>';
Exemplo n.º 6
0
            $solde = 0;

            // Boucle sur chaque facture
            for ($i = 0 ; $i < $num ; $i++)
	      {
		$objf = $db->fetch_object($resql);

		$fac = new Facture($db);
		$ret=$fac->fetch($objf->facid);
                if ($ret < 0)
		  {
		    print $fac->error."<br>";
		    continue;
		  }
		$totalpaye = $fac->getSommePaiement();

                $var=!$var;
                print "<tr $bc[$var]>";

                print "<td align=\"center\">".dol_print_date($fac->date)."</td>\n";
                print "<td><a href=\"../compta/facture.php?facid=$fac->id\">".img_object($langs->trans("ShowBill"),"bill")." ".$fac->ref."</a></td>\n";

    			print '<td aling="left">'.$fac->getLibStatut(2,$totalpaye).'</td>';
                print '<td align="right">'.price($fac->total_ttc)."</td>\n";
                $solde = $solde + $fac->total_ttc;

                print '<td align="right">&nbsp;</td>';
                print '<td align="right">'.price($solde)."</td>\n";

		// Auteur
Exemplo n.º 7
0
	require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");

	$invoice=new Facture($db);
	$result=$invoice->fetch('',$_REQUEST["ref"]);
	if ($result < 0)
	{
		$mesg=$invoice->error;
		$error++;
	}
	else
	{
		$result=$invoice->fetch_thirdparty($invoice->socid);
	}

	$amount=$invoice->total_ttc - $invoice->getSommePaiement();
    if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
    $amount=price2num($amount);

	$fulltag='IR='.$invoice->ref.'.TPID='.$invoice->client->id.'.TP='.strtr($invoice->client->nom,"-"," ");
	if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $fulltag.='.TAG='.$_REQUEST["tag"]; }
	$fulltag=dol_string_unaccent($fulltag);

	// Creditor
	$var=!$var;
	print '<tr><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Creditor");
    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$creditor.'</b>';
    print '<input type="hidden" name="creditor" value="'.$creditor.'">';
    print '</td></tr>'."\n";

	// Debitor
Exemplo n.º 8
0
if ($resql) {
    $num = $db->num_rows($resql);
    $i = 0;
    print '<table class="noborder" width="100%">';
    print '<tr class="liste_titre">';
    print '<td colspan="5">' . $langs->trans("InvoiceWaitingWithdraw") . ' (' . $num . ')</td></tr>';
    if ($num) {
        $var = True;
        while ($i < $num && $i < 20) {
            $obj = $db->fetch_object($resql);
            $invoicestatic->id = $obj->rowid;
            $invoicestatic->ref = $obj->facnumber;
            $invoicestatic->statut = $obj->fk_statut;
            $invoicestatic->paye = $obj->paye;
            $invoicestatic->type = $obj->type;
            $alreadypayed = $invoicestatic->getSommePaiement();
            $var = !$var;
            print '<tr ' . $bc[$var] . '><td>';
            print $invoicestatic->getNomUrl(1, 'withdraw');
            print '</td>';
            print '<td>';
            $thirdpartystatic->id = $obj->socid;
            $thirdpartystatic->name = $obj->name;
            print $thirdpartystatic->getNomUrl(1, 'customer');
            print '</td>';
            print '<td align="right">';
            print price($obj->amount);
            print '</td>';
            print '<td align="right">';
            print dol_print_date($db->jdate($obj->date_demande), 'day');
            print '</td>';
 /**
  * Fill the body of email's message with a facture
  *
  * @param int $id
  *
  * @return string		String with ticket data
  */
 public static function fillMailFactureBody($id)
 {
     global $db, $conf, $langs, $mysoc;
     $langs->Load("rewards@rewards");
     $facture = new Facture($db);
     $res = $facture->fetch($id);
     $mysoc = new Societe($db);
     $mysoc->fetch($facture->socid);
     $userstatic = new User($db);
     $userstatic->fetch($facture->user_valid);
     $label = $facture->ref;
     $message = $conf->global->MAIN_INFO_SOCIETE_NOM . " \n" . $conf->global->MAIN_INFO_SOCIETE_ADRESSE . " \n" . $conf->global->MAIN_INFO_SOCIETE_CP . ' ' . $conf->global->MAIN_INFO_SOCIETE_VILLE . " \n\n";
     $message .= $label . " \n" . dol_print_date($facture->date_creation, 'dayhourtext') . " \n";
     $message .= $langs->transnoentities("Vendor") . ': ' . $userstatic->fistname . " " . $userstatic->lastname . "\n";
     $sql = "SELECT fk_place,fk_cash FROM " . MAIN_DB_PREFIX . "pos_facture WHERE fk_facture =" . $facture->id;
     $result = $db->query($sql);
     if ($result) {
         $objp = $db->fetch_object($result);
         if ($objp->fk_place > 0) {
             $place = new Place($db);
             $place->fetch($objp->fk_place);
             $message .= $langs->trans("Place") . ': ' . $place->name . "\n";
         }
     }
     $message .= "\n";
     $message .= $langs->transnoentities("Label") . "\t\t\t\t\t\t" . $langs->transnoentities("Qty") . "/" . $langs->transnoentities("Price") . "\t\t" . $langs->transnoentities("Total") . "\n";
     //$facture->getLinesArray();
     if (!empty($facture->lines)) {
         $subtotal = 0;
         foreach ($facture->lines as $line) {
             $espacio = '';
             $totalline = $line->qty * $line->subprice;
             if (empty($line->libelle)) {
                 $line->libelle = $line->description;
             }
             while (dol_strlen(dol_trunc($line->libelle, 30) . $espacio) < 29) {
                 $espacio .= "    \t";
             }
             $message .= dol_trunc($line->libelle, 33) . $espacio;
             $message .= "\t\t" . $line->qty . " * " . price($line->subprice) . "\t\t" . price($line->total_ht) . ' ' . $langs->trans(currency_name($conf->currency)) . "\n";
             $subtotal[$line->tva_tx] += $line->total_ht;
             $subtotaltva[$line->tva_tx] += $line->total_tva;
             if (!empty($line->total_localtax1)) {
                 $localtax1 = $line->localtax1_tx;
             }
             if (!empty($line->total_localtax2)) {
                 $localtax2 = $line->localtax2_tx;
             }
         }
     } else {
         $message .= $langs->transnoentities("ErrNoArticles") . "\n";
     }
     $message .= $langs->transnoentities("TotalTTC") . ":\t" . price($facture->total_ttc) . " " . $langs->trans(currency_name($conf->currency)) . "\n";
     $message .= "\n" . $langs->trans("TotalHT") . "\t" . $langs->trans("VAT") . "\t" . $langs->trans("TotalVAT") . "\n";
     if (!empty($subtotal)) {
         foreach ($subtotal as $totkey => $totval) {
             if ($tvakey > 0) {
                 $message .= price($subtotal[$totkey], "", "", "", "", 2) . "\t\t\t" . price($totkey, "", "", "", "", 2) . "%\t" . price($subtotaltva[$totkey], "", "", "", "", 2) . "\n";
             }
         }
     }
     $message .= "-------------------------------\n";
     $message .= price($facture->total_ht, "", "", "", "", 2) . "\t\t\t----\t" . price($facture->total_tva, "", "", "", "", 2) . "\n";
     if ($facture->total_localtax1 != 0) {
         $message .= $langs->transcountrynoentities("TotalLT1", $mysoc->country_code) . " " . price($localtax1, "", "", "", "", 2) . "%\t" . price($facture->total_localtax1, "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n";
     }
     if ($facture->total_localtax2 != 0) {
         $message .= $langs->transcountrynoentities("TotalLT2", $mysoc->country_code) . " " . price($localtax2, "", "", "", "", 2) . "%\t" . price($facture->total_localtax2, "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n";
     }
     $message .= "\n\n";
     $terminal = new Cash($db);
     $sql = 'SELECT fk_cash, customer_pay FROM ' . MAIN_DB_PREFIX . 'pos_facture WHERE fk_facture = ' . $facture->id;
     $resql = $db->query($sql);
     $obj = $db->fetch_object($resql);
     $customer_pay = $obj->customer_pay;
     $terminal->fetch($obj > fk_cash);
     if (!empty($conf->rewards->enabled)) {
         $rewards = new Rewards($db);
         $points = $rewards->getInvoicePoints($facture->id);
     }
     if ($facture->type == 0) {
         $pay = $facture->getSommePaiement();
         if (!empty($conf->rewards->enabled)) {
             $usepoints = abs($rewards->getInvoicePoints($facture->id, 1));
             $moneypoints = abs($usepoints * $conf->global->REWARDS_DISCOUNT);
             //falta fer algo per aci
             if ($customer_pay > $pay - $moneypoints) {
                 $pay = $customer_pay;
             } else {
                 $pay = $pay - $moneypoints;
             }
         } else {
             if ($customer_pay > $pay) {
                 $pay = $customer_pay;
             }
         }
     }
     if ($facture->type == 2) {
         $customer_pay = $customer_pay * -1;
         $pay = $facture->getSommePaiement();
         if (!empty($conf->rewards->enabled)) {
             $usepoints = abs($rewards->getInvoicePoints($facture->id, 1));
             $moneypoints = abs($usepoints * $conf->global->REWARDS_DISCOUNT);
             //falta fer algo per aci
             if ($customer_pay > $pay - $moneypoints) {
                 $pay = $customer_pay;
             } else {
                 $pay = $pay - $moneypoints;
             }
         } else {
             if ($customer_pay > $pay) {
                 $pay = $customer_pay;
             }
         }
     }
     $diff_payment = $facture->total_ttc - $moneypoints - $pay;
     $listofpayments = $facture->getListOfPayments();
     foreach ($listofpayments as $paym) {
         if ($paym['type'] != 'PNT') {
             if ($paym['type'] != 'LIQ') {
                 $message .= $terminal->select_Paymentname(dol_getIdFromCode($db, $paym['type'], 'c_paiement')) . "\t" . price($paym['amount'], "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n";
             } else {
                 $message .= $terminal->select_Paymentname(dol_getIdFromCode($db, $paym['type'], 'c_paiement')) . "\t" . price($paym['amount'] - ($diff_payment < 0 ? $diff_payment : 0), "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n";
             }
         }
     }
     if (!empty($conf->rewards->enabled)) {
         if ($moneypoints > 0) {
             $message .= $usepoints . " " . $langs->trans("Points") . "\t" . price($moneypoints, "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n";
         }
     }
     $message .= ($diff_payment < 0 ? $langs->trans("CustomerRet") : $langs->trans("CustomerDeb")) . "\t" . price(abs($diff_payment), "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n";
     if ($points != 0 && !empty($conf->rewards->enabled)) {
         $message .= $langs->trans("TotalPointsInvoice") . "\t" . price($points, "", "", "", "", 2) . " " . $langs->trans('Points') . "\n";
         $total_points = $rewards->getCustomerPoints($facture->socid);
         $message .= $langs->trans("DispoPoints") . "\t" . price($total_points, "", "", "", "", 2) . " " . $langs->trans('Points') . "\n";
     }
     $message .= $conf->global->POS_PREDEF_MSG;
     return $message;
 }
     $json_data['localtax2'] = $langs->transcountrynoentities("TotalLT2", $mysoc->country_code) . " " . price($localtax2, "", "", "", "", 2) . "% " . price($facture->total_localtax2, "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency));
 } else {
     $json_data['localtax2'] = "";
 }
 $terminal = new Cash($db);
 $sql = 'SELECT fk_cash, customer_pay FROM ' . MAIN_DB_PREFIX . 'pos_facture WHERE fk_facture = ' . $facture->id;
 $resql = $db->query($sql);
 $obj = $db->fetch_object($resql);
 $customer_pay = $obj->customer_pay;
 $terminal->fetch($obj > fk_cash);
 if (!empty($conf->rewards->enabled)) {
     $rewards = new Rewards($db);
     $points = $rewards->getInvoicePoints($facture->id);
 }
 if ($facture->type == 0) {
     $pay = $facture->getSommePaiement();
     if (!empty($conf->rewards->enabled)) {
         $usepoints = abs($rewards->getInvoicePoints($facture->id, 1));
         $moneypoints = abs($usepoints * $conf->global->REWARDS_DISCOUNT);
         //falta fer algo per aci
         if ($customer_pay > $pay - $moneypoints) {
             $pay = $customer_pay;
         } else {
             $pay = $pay - $moneypoints;
         }
     } else {
         if ($customer_pay > $pay) {
             $pay = $customer_pay;
         }
     }
 }
Exemplo n.º 11
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;
	}
		<table class="totpay">
		<?php 
echo '<tr><td></td></tr>';
echo '<tr><td></td></tr>';
$terminal = new Cash($db);
$sql = 'SELECT fk_cash, customer_pay FROM ' . MAIN_DB_PREFIX . 'pos_facture WHERE fk_facture = ' . $object->id;
$resql = $db->query($sql);
$obj = $db->fetch_object($resql);
$customer_pay = $obj->customer_pay;
$terminal->fetch($obj > fk_cash);
if (!empty($conf->rewards->enabled)) {
    $rewards = new Rewards($db);
    $points = $rewards->getInvoicePoints($object->id);
}
if ($object->type == 0) {
    $pay = $object->getSommePaiement();
    if (!empty($conf->rewards->enabled)) {
        $usepoints = abs($rewards->getInvoicePoints($object->id, 1));
        $moneypoints = abs($usepoints * $conf->global->REWARDS_DISCOUNT);
        //falta fer algo per aci
        if ($customer_pay > $pay - $moneypoints) {
            $pay = $customer_pay;
        } else {
            $pay = $pay - $moneypoints;
        }
    } else {
        if ($customer_pay > $pay) {
            $pay = $customer_pay;
        }
    }
}
Exemplo n.º 13
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.º 14
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');
Exemplo n.º 15
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;
		}
	}
Exemplo n.º 16
0
					$paiement = -1*$facturefournstatic->getSommePaiement();	// Payment already done
				}
			}
			if ($obj->family == 'invoice')
			{
				$facturestatic->ref=$obj->ref;
				$facturestatic->id=$obj->objid;
				$facturestatic->type=$obj->type;
				$ref = $facturestatic->getNomUrl(1,'');

				$societestatic->id = $obj->socid;
				$societestatic->nom = $obj->nom;
				$refcomp=$societestatic->getNomUrl(1,'',24);

				$paiement = $facturestatic->getSommePaiement();	// Payment already done
			}
			if ($obj->family == 'social_contribution')
			{
				$socialcontribstatic->ref=$obj->ref;
				$socialcontribstatic->id=$obj->objid;
				$socialcontribstatic->lib=$obj->type;
				$ref = $socialcontribstatic->getNomUrl(1,24);

				$paiement = -1*$socialcontribstatic->getSommePaiement();	// Payment already done
			}

			$total_ttc = $obj->total_ttc;
			if ($paiement) $total_ttc = $obj->total_ttc - $paiement;
			$solde += $total_ttc;