";
print '| '.dol_print_date($obj->dc,'dayhour').' | ';
- print '';
if ($obj->description == '(CREDIT_NOTE)')
{
+ print ' | ';
$facturestatic->id=$obj->fk_facture_source;
$facturestatic->ref=$obj->ref;
$facturestatic->type=$obj->type;
print $langs->trans("CreditNote").' '.$facturestatic->getNomURl(1);
+ print ' | ';
}
elseif ($obj->description == '(DEPOSIT)')
{
+ print '';
$facturestatic->id=$obj->fk_facture_source;
$facturestatic->ref=$obj->ref;
$facturestatic->type=$obj->type;
print $langs->trans("InvoiceDeposit").' '.$facturestatic->getNomURl(1);
+ print ' | ';
}
else
{
+ print '';
print $obj->description;
+ print ' | ';
}
- print '';
- print ''.price($obj->amount_ht).' | ';
+ print ''.$langs->trans("NotConsumed").' | ';
+ print ''.price($obj->amount_ht).' | ';
print ''.price2num($obj->tva_tx,'MU').'% | ';
print ''.price($obj->amount_ttc).' | ';
print '';
- print ''.img_object($langs->trans("ShowUser"),'user').' '.$obj->login;
+ print ''.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'';
print ' | ';
- if ($obj->user_id == $user->id) print 'id.'&action=remove&remid='.$obj->rowid.'">'.img_delete($langs->trans("RemoveDiscount")).' | ';
+ if ($obj->user_id == $user->id) print 'id.'&action=remove&remid='.$obj->rowid.'">'.img_delete($langs->trans("RemoveDiscount")).' | ';
else print ' | ';
print '
';
$i++;
@@ -251,8 +264,9 @@ if ($_socid > 0)
print '';
- print '| '.$langs->trans("Date").' | ';
- print ''.$langs->trans("ReasonDiscount").' | ';
- print ''.$langs->trans("Invoice").' | ';
+ print '
';
+ print '| '.$langs->trans("Date").' | ';
+ print ''.$langs->trans("ReasonDiscount").' | ';
+ print ''.$langs->trans("ConsumedBy").' | ';
print ''.$langs->trans("AmountHT").' | ';
print ''.$langs->trans("VATRate").' | ';
print ''.$langs->trans("AmountTTC").' | ';
- print ''.$langs->trans("Author").' | ';
+ print ''.$langs->trans("Author").' | ';
print ' | ';
print '
';
@@ -335,32 +350,36 @@ if ($_socid > 0)
$var = !$var;
print "";
print '| '.dol_print_date($obj->dc,'dayhour').' | ';
- print '';
if ($obj->description == '(CREDIT_NOTE)')
{
+ print ' | ';
$facturestatic->id=$obj->fk_facture_source;
$facturestatic->ref=$obj->ref;
$facturestatic->type=$obj->type;
print $langs->trans("CreditNote").' '.$facturestatic->getNomURl(1);
+ print ' | ';
}
elseif ($obj->description == '(DEPOSIT)')
{
+ print '';
$facturestatic->id=$obj->fk_facture_source;
$facturestatic->ref=$obj->ref;
$facturestatic->type=$obj->type;
print $langs->trans("InvoiceDeposit").' '.$facturestatic->getNomURl(1);
+ print ' | ';
}
else
{
+ print '';
print $obj->description;
+ print ' | ';
}
- print '';
- print ''.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.' | ';
+ print ''.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.' | ';
print ''.price($obj->amount_ht).' | ';
print ''.price2num($obj->tva_tx,'MU').'% | ';
print ''.price($obj->amount_ttc).' | ';
print '';
- print ''.img_object($langs->trans("ShowUser"),'user').' '.$obj->login;
+ print ''.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.'';
print ' | ';
print ' | ';
print '
';
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 885b8d705bc..eb18aa19651 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -2156,10 +2156,11 @@ else
}
if ($fac->type == 2)
{
- $facreplaced=new Facture($db);
- $facreplaced->fetch($fac->fk_facture_source);
- print ' ('.$langs->transnoentities("CorrectInvoice",$facreplaced->getNomUrl(1)).')';
+ $facusing=new Facture($db);
+ $facusing->fetch($fac->fk_facture_source);
+ print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
}
+
$facidavoir=$fac->getListIdAvoirFromInvoice();
if (sizeof($facidavoir) > 0)
{
@@ -2192,7 +2193,15 @@ else
{
if ($fac->statut > 0 || $fac->type == 2 || $fac->type == 3)
{
- print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)).'. ';
+ if ($fac->statut == 0)
+ {
+ print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)).'. ';
+ }
+ else
+ {
+ $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie));
+ print $html->textwithhelp($text,$langs->trans("AbsoluteDiscountUse"));
+ }
}
else
{
@@ -2207,8 +2216,12 @@ else
// If validated, we show link "add credit note to payment"
if ($fac->statut != 1 || $fac->type == 2 || $fac->type == 3)
{
- $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie));
- print $html->textwithhelp($text,$langs->trans("CreditNoteDepositUse"));
+ if ($fac->statut == 0 && $fac->type != 3)
+ {
+ $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie));
+ print $html->textwithhelp($text,$langs->trans("CreditNoteDepositUse"));
+ }
+ else print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)).'.';
}
else
{
@@ -2254,9 +2267,89 @@ else
print '';
+ print '';
+
+ // List of payments already done
+ print '';
+ print '| '.($fac->type == 2 ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).' | ';
+ print ''.$langs->trans('Type').' | ';
+ print ''.$langs->trans('Amount').' | ';
+ print ' | ';
+ print ' ';
+
+ $var=true;
+
/*
* List of payments
*/
+
+ // Payments already done (from deposits)
+ /*
+ $depositamount=0;
+ $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
+ $sql.= " re.description, re.fk_facture_source, re.fk_facture_source";
+ $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
+ $sql.= " WHERE fk_facture = ".$fac->id;
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $numdeposits = $db->num_rows($resql);
+ $i = 0;
+ $invoice=new Facture($db);
+ // Loop on each deposit applied
+ while ($i < $numdeposits)
+ {
+ $objinvoice = $db->fetch_object($resql);
+ $invoice->fetch($objinvoice->fk_facture_source);
+ if ($invoice->type != 3) continue; // only deposits
+
+ // For each deposits, get payments
+ $sql = 'SELECT '.$db->pdate('datep').' as dp, pf.amount,';
+ $sql.= ' c.libelle as paiement_type, p.num_paiement, p.rowid';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf';
+ $sql.= ' WHERE pf.fk_facture = '.$invoice->id.' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
+ $sql.= ' ORDER BY dp, tms';
+
+ $resqlpayment = $db->query($sql);
+ if ($resqlpayment)
+ {
+ $numpayments = $db->num_rows($resqlpayment);
+ $j = 0;
+ while ($j < $numpayments)
+ {
+ $objpayment = $db->fetch_object($resqlpayement);
+ $var=!$var;
+
+ print '| ';
+ print ''.img_object($langs->trans('ShowPayment'),'payment').' ';
+ print dol_print_date($objpayment->dp,'day').'';
+
+ print ' ('.$langs->trans("Deposit").' ';
+ print $invoice->getNomUrl(0).')';
+
+ print ' | ';
+ print ''.$objpayment->paiement_type.' '.$objpayement->num_paiement.' | ';
+ print ''.price($objpayment->amount).' | ';
+ // Remove deposit invoice
+ print '';
+ print 'id.'&action=unlinkdiscount&discountid='.$objinvoice->rowid.'">'.img_delete().'';
+ print ' | ';
+ print ' ';
+
+ $j++;
+ $depositamount += $obj->amount;
+ }
+ }
+ $i++;
+ }
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+ */
+
+ // Payments already done (from payment on this invoice)
$sql = 'SELECT '.$db->pdate('datep').' as dp, pf.amount,';
$sql.= ' c.libelle as paiement_type, p.num_paiement, p.rowid';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf';
@@ -2268,19 +2361,9 @@ else
{
$num = $db->num_rows($result);
$i = 0;
- print '';
-
- // List of payments already done
- print '';
- print '| '.($fac->type == 2 ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).' | ';
- print ''.$langs->trans('Type').' | ';
- print ''.$langs->trans('Amount').' | ';
- print ' | ';
- print ' ';
if ($fac->type != 2)
{
- $var=True;
while ($i < $num)
{
$objp = $db->fetch_object($result);
@@ -2294,97 +2377,7 @@ else
print '';
$i++;
}
-
- // Already payed
- print '| '.$langs->trans('AlreadyPayed').' : | '.price($totalpaye).' | | ';
-
- // Billed
- print '| '.$langs->trans("Billed").' : | '.price($fac->total_ttc).' | | ';
- $resteapayeraffiche=$resteapayer;
-
- $creditnoteamount=0;
-
- // Loop on each credit note applied
- $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
- $sql.= " re.description, re.fk_facture_source, re.fk_facture_source";
- $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
- $sql.= " WHERE fk_facture = ".$fac->id;
- $resql=$db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- $i = 0;
- $invoice=new Facture($db);
- while ($i < $num)
- {
- $obj = $db->fetch_object($resql);
- $invoice->fetch($obj->fk_facture_source);
- print '| ';
- if ($invoice->type == 2) print $langs->trans("CreditNote").' ';
- if ($invoice->type == 3) print $langs->trans("Deposit").' ';
- print $invoice->getNomUrl(0);
- print ' : | ';
- print ''.price($obj->amount_ttc).' | ';
- print '';
- print 'id.'&action=unlinkdiscount&discountid='.$obj->rowid.'">'.img_delete().'';
- print ' | ';
- $i++;
- $creditnoteamount += $obj->amount_ttc;
- }
- }
- else
- {
- dol_print_error($db);
- }
-
- // Payé partiellement 'escompte'
- if (($fac->statut == 2 || $fac->statut == 3) && $fac->close_code == 'discount_vat')
- {
- print '| ';
- print $html->textwithhelp($langs->trans("Escompte").':',$langs->trans("HelpEscompte"),-1);
- print ' | '.price($fac->total_ttc - $creditnoteamount - $totalpaye).' | | ';
- $resteapayeraffiche=0;
- }
- // Payé partiellement ou Abandon 'badcustomer'
- if (($fac->statut == 2 || $fac->statut == 3) && $fac->close_code == 'badcustomer')
- {
- print '| ';
- print $html->textwithhelp($langs->trans("Abandoned").':',$langs->trans("HelpAbandonBadCustomer"),-1);
- print ' | '.price($fac->total_ttc - $creditnoteamount - $totalpaye).' | | ';
- //$resteapayeraffiche=0;
- }
- // Payé partiellement ou Abandon 'product_returned'
- if (($fac->statut == 2 || $fac->statut == 3) && $fac->close_code == 'product_returned')
- {
- print '| ';
- print $html->textwithhelp($langs->trans("ProductReturned").':',$langs->trans("HelpAbandonProductReturned"),-1);
- print ' | '.price($fac->total_ttc - $creditnoteamount - $totalpaye).' | | ';
- $resteapayeraffiche=0;
- }
- // Payé partiellement ou Abandon 'abandon'
- if (($fac->statut == 2 || $fac->statut == 3) && $fac->close_code == 'abandon')
- {
- print '';
- $text=$langs->trans("HelpAbandonOther");
- if ($fac->close_note) $text.='
'.$langs->trans("Reason").':'.$fac->close_note;
- print $html->textwithhelp($langs->trans("Abandoned").':',$text,-1);
- print ' | '.price($fac->total_ttc - $creditnoteamount - $totalpaye).' | | ';
- $resteapayeraffiche=0;
- }
- print '| ';
- if ($resteapayeraffiche >= 0) print $langs->trans('RemainderToPay');
- else print $langs->trans('ExcessReceived');
- print ' : | ';
- print ''.price($resteapayeraffiche).' | ';
- print ' | ';
}
- else
- {
- // Sold credit note
- print '| '.$langs->trans('TotalTTCToYourCredit').' : | ';
- print ''.price(abs($fac->total_ttc)).' | | ';
- }
- print ' ';
$db->free($result);
}
else
@@ -2392,6 +2385,107 @@ else
dol_print_error($db);
}
+ if ($fac->type != 2)
+ {
+ // Total already payed
+ print '| ';
+ if ($fac->type != 3) print $langs->trans('AlreadyPayedNoCreditNotesNoDeposits');
+ else print $langs->trans('AlreadyPayed');
+ print ' : | '.price($totalpaye).' | | ';
+
+ $resteapayeraffiche=$resteapayer;
+
+ // 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, re.fk_facture_source";
+ $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
+ $sql.= " WHERE fk_facture = ".$fac->id;
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i = 0;
+ $invoice=new Facture($db);
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+ $invoice->fetch($obj->fk_facture_source);
+ print '| ';
+ if ($invoice->type == 2) print $langs->trans("CreditNote").' ';
+ if ($invoice->type == 3) print $langs->trans("Deposit").' ';
+ print $invoice->getNomUrl(0);
+ print ' : | ';
+ print ''.price($obj->amount_ttc).' | ';
+ print '';
+ print 'id.'&action=unlinkdiscount&discountid='.$obj->rowid.'">'.img_delete().'';
+ print ' | ';
+ $i++;
+ if ($invoice->type == 2) $creditnoteamount += $obj->amount_ttc;
+ if ($invoice->type == 3) $depositamount += $obj->amount_ttc;
+ }
+ }
+ else
+ {
+ dol_print_error($db);
+ }
+
+ // Payé partiellement 'escompte'
+ if (($fac->statut == 2 || $fac->statut == 3) && $fac->close_code == 'discount_vat')
+ {
+ print '| ';
+ print $html->textwithhelp($langs->trans("Escompte").':',$langs->trans("HelpEscompte"),-1);
+ print ' | '.price($fac->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
+ $resteapayeraffiche=0;
+ }
+ // Payé partiellement ou Abandon 'badcustomer'
+ if (($fac->statut == 2 || $fac->statut == 3) && $fac->close_code == 'badcustomer')
+ {
+ print '| ';
+ print $html->textwithhelp($langs->trans("Abandoned").':',$langs->trans("HelpAbandonBadCustomer"),-1);
+ print ' | '.price($fac->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
+ //$resteapayeraffiche=0;
+ }
+ // Payé partiellement ou Abandon 'product_returned'
+ if (($fac->statut == 2 || $fac->statut == 3) && $fac->close_code == 'product_returned')
+ {
+ print '| ';
+ print $html->textwithhelp($langs->trans("ProductReturned").':',$langs->trans("HelpAbandonProductReturned"),-1);
+ print ' | '.price($fac->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
+ $resteapayeraffiche=0;
+ }
+ // Payé partiellement ou Abandon 'abandon'
+ if (($fac->statut == 2 || $fac->statut == 3) && $fac->close_code == 'abandon')
+ {
+ print '';
+ $text=$langs->trans("HelpAbandonOther");
+ if ($fac->close_note) $text.='
'.$langs->trans("Reason").':'.$fac->close_note;
+ print $html->textwithhelp($langs->trans("Abandoned").':',$text,-1);
+ print ' | '.price($fac->total_ttc - $creditnoteamount - $depositamount - $totalpaye).' | | ';
+ $resteapayeraffiche=0;
+ }
+
+ // Billed
+ print '| '.$langs->trans("Billed").' : | '.price($fac->total_ttc).' | | ';
+
+ // Remainder to pay
+ print '| ';
+ if ($resteapayeraffiche >= 0) print $langs->trans('RemainderToPay');
+ else print $langs->trans('ExcessReceived');
+ print ' : | ';
+ print ''.price($resteapayeraffiche).' | ';
+ print ' | ';
+ }
+ else
+ {
+ // Sold credit note
+ print '| '.$langs->trans('TotalTTCToYourCredit').' : | ';
+ print ''.price(abs($fac->total_ttc)).' | | ';
+ }
+
+ print ' ';
+
print ' | ';
// Date payment term
@@ -2975,10 +3069,10 @@ else
// Validate
if ($fac->statut == 0 && $num_lignes > 0 &&
- (
- (($fac->type == 0 || $fac->type == 1 || $fac->type == 3 || $fac->type == 4) && $fac->total_ttc >= 0)
- || ($fac->type == 2 && $fac->total_ttc <= 0))
- )
+ (
+ (($fac->type == 0 || $fac->type == 1 || $fac->type == 3 || $fac->type == 4) && $fac->total_ttc >= 0)
+ || ($fac->type == 2 && $fac->total_ttc <= 0))
+ )
{
if ($user->rights->facture->valider)
{
diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php
index 0495fa8ca95..63ba8b5d21b 100644
--- a/htdocs/compta/paiement/fiche.php
+++ b/htdocs/compta/paiement/fiche.php
@@ -46,7 +46,7 @@ $mesg='';
if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->facture->paiement)
{
$db->begin();
-
+
$paiement = new Paiement($db);
$paiement->fetch($_GET['id']);
$result = $paiement->delete();
@@ -72,7 +72,7 @@ if ($_POST['action'] == 'confirm_valide' && $_POST['confirm'] == 'yes' && $user-
if ($paiement->valide() > 0)
{
$db->commit();
-
+
// \TODO Boucler sur les facture liées à ce paiement et régénèrer le pdf
$factures=array();
foreach($factures as $id)
@@ -121,11 +121,11 @@ $h=0;
$head[$h][0] = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$_GET["id"];
$head[$h][1] = $langs->trans("Card");
$hselected = $h;
-$h++;
+$h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/paiement/info.php?id='.$_GET["id"];
$head[$h][1] = $langs->trans("Info");
-$h++;
+$h++;
dol_fiche_head($head, $hselected, $langs->trans("PaymentCustomerInvoice"));
@@ -180,15 +180,15 @@ print '| '.$langs->trans('Note').' | '.nl2b
// Bank account
if ($conf->banque->enabled)
{
- if ($paiement->bank_account)
+ if ($paiement->bank_account)
{
$bankline=new AccountLine($db);
$bankline->fetch($paiement->bank_line);
-
+
print ' |
';
print '| '.$langs->trans('BankTransactionLine').' | ';
print '';
- print $bankline->getNomUrl(1,0,'showall');
+ print $bankline->getNomUrl(1,0,'showall');
print ' | ';
print '
';
}
@@ -201,15 +201,15 @@ print '
';
* Liste des factures
*/
$allow_delete = 1 ;
-$sql = 'SELECT f.facnumber, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom, s.rowid as socid';
+$sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.total_ttc, f.paye, f.fk_statut, pf.amount, s.nom, s.rowid as socid';
$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s';
$sql .= ' WHERE pf.fk_facture = f.rowid AND f.fk_soc = s.rowid';
$sql .= ' AND pf.fk_paiement = '.$paiement->id;
-$resql=$db->query($sql);
+$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
-
+
$i = 0;
$total = 0;
print '