From de8ed22448933b0211fb01abc00da8ddd834df7e Mon Sep 17 00:00:00 2001 From: aspangaro Date: Wed, 2 Nov 2016 07:13:17 +0100 Subject: [PATCH] Work on supplier credit/deposit/replacement invoice --- .../fourn/class/fournisseur.facture.class.php | 2 +- htdocs/fourn/facture/card.php | 139 +++++++++++++++++- 2 files changed, 132 insertions(+), 9 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 9b3de478cc9..5241105a90e 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -10,7 +10,7 @@ * Copyright (C) 2014-2016 Marcos GarcĂ­a * Copyright (C) 2015 Bahfir Abbes * Copyright (C) 2015 Ferran Marcet - * Copyright (C) 2016 Alexandre Spangaro + * Copyright (C) 2016 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 1fbbe41978b..e301c7aaa13 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -486,10 +486,10 @@ if (empty($reshook)) { // Reset fk_parent_line for no child products and special product if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) { - $fk_parent_line = 0; + $fk_parent_line = 0; } - $line->fk_facture = $object->id; + $line->fk_facture_fourn = $object->id; $line->fk_parent_line = $fk_parent_line; $line->subprice =-$line->subprice; // invert price for object @@ -2391,7 +2391,8 @@ else { print ''.$langs->trans("None").''; } - + + /* if ($object->paye == 0) { print ''.$langs->trans('AlreadyPaid').' :'.price($totalpaye).''; @@ -2402,7 +2403,8 @@ else print ''.$langs->trans('RemainderToPay').' :'; print ''.price($resteapayer).''; } - print ''; + */ + $db->free($result); } else @@ -2410,6 +2412,131 @@ else dol_print_error($db); } + if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE) { + // Total already paid + print ''; + if ($object->type != FactureFournisseur::TYPE_DEPOSIT) + print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits'); + else + print $langs->trans('AlreadyPaid'); + print ' : 0)?' class="amountalreadypaid"':'').'>' . price($totalpaye) . ' '; + + $resteapayeraffiche = $resteapayer; + $cssforamountpaymentcomplete = 'amountpaymentcomplete'; + + // Loop on each credit note or deposit amount applied + $creditnoteamount = 0; + $depositamount = 0; + $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; + $sql .= " re.description, re.fk_facture_source"; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re"; + $sql .= " WHERE fk_facture = " . $object->id; + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + $invoice = new FactureFournisseur($db); + while ($i < $num) { + $obj = $db->fetch_object($resql); + $invoice->fetch($obj->fk_facture_source); + print ''; + if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) + print $langs->trans("CreditNote") . ' '; + if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) + print $langs->trans("Deposit") . ' '; + print $invoice->getNomUrl(0); + print ' :'; + print '' . price($obj->amount_ttc) . ''; + print ''; + print 'rowid . '">' . img_delete() . ''; + print ''; + $i ++; + if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) + $creditnoteamount += $obj->amount_ttc; + if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) + $depositamount += $obj->amount_ttc; + } + } else { + dol_print_error($db); + } + + // Paye partiellement 'escompte' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'discount_vat') { + print ''; + print $form->textwithpicto($langs->trans("Discount") . ':', $langs->trans("HelpEscompte"), - 1); + print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' '; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = ''; + } + // Paye partiellement ou Abandon 'badsupplier' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'badsupplier') { + print ''; + print $form->textwithpicto($langs->trans("Abandoned") . ':', $langs->trans("HelpAbandonBadCustomer"), - 1); + print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' '; + // $resteapayeraffiche=0; + $cssforamountpaymentcomplete = ''; + } + // Paye partiellement ou Abandon 'product_returned' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'product_returned') { + print ''; + print $form->textwithpicto($langs->trans("ProductReturned") . ':', $langs->trans("HelpAbandonProductReturned"), - 1); + print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' '; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = ''; + } + // Paye partiellement ou Abandon 'abandon' + if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'abandon') { + print ''; + $text = $langs->trans("HelpAbandonOther"); + if ($object->close_note) + $text .= '

' . $langs->trans("Reason") . ':' . $object->close_note; + print $form->textwithpicto($langs->trans("Abandoned") . ':', $text, - 1); + print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' '; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = ''; + } + + // Billed + print '' . $langs->trans("Billed") . ' :' . price($object->total_ttc) . ' '; + + // Remainder to pay + print ''; + if ($resteapayeraffiche >= 0) + print $langs->trans('RemainderToPay'); + else + print $langs->trans('ExcessReceived'); + print ' :'; + print '' . price($resteapayeraffiche) . ''; + print ' '; + } + else // Credit note + { + // Total already paid back + print ''; + print $langs->trans('AlreadyPaidBack'); + print ' :' . price($sign * $totalpaye) . ' '; + + // Billed + print '' . $langs->trans("Billed") . ' :' . price($sign * $object->total_ttc) . ' '; + + // Remainder to pay back + print ''; + if ($resteapayeraffiche <= 0) + print $langs->trans('RemainderToPayBack'); + else + print $langs->trans('ExcessPaydBack'); + print ' :'; + print '' . price($sign * $resteapayeraffiche) . ''; + print ' '; + + // Sold credit note + // print ''.$langs->trans('TotalTTC').' :'; + // print ''.price($sign * + // $object->total_ttc).' '; + } + + print ''; + print ''; print ''; print ''; @@ -2435,9 +2562,6 @@ else /* * Lines */ - //$result = $object->getLinesArray(); - - print '
'; print ''; print ''; @@ -2526,7 +2650,6 @@ else else print ''.$langs->trans('SendByMail').''; } - // Make payments if ($action != 'edit' && $object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $user->societe_id == 0) {