Fix: Several fix.
New: Also allow to enter a payment with a negative value on an invoice and positive onto other.
This commit is contained in:
parent
8ff506b120
commit
153997432f
@ -502,11 +502,11 @@ if ($id > 0)
|
||||
$sql2.= ' AND s.rowid = '.$object->id;
|
||||
// Show orders with status validated, shipping started and delivered (well any order we can bill)
|
||||
$sql2.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
|
||||
|
||||
|
||||
$resql2=$db->query($sql2);
|
||||
$orders2invoice = $db->num_rows($resql2);
|
||||
$db->free($resql2);
|
||||
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
@ -776,14 +776,18 @@ if ($id > 0)
|
||||
{
|
||||
if ($user->rights->facture->creer)
|
||||
{
|
||||
$langs->load("bills");
|
||||
|
||||
if($orders2invoice > 0) print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$object->id.'">'.$langs->trans("CreateInvoiceForThisCustomer").'</a>';
|
||||
else print '<a class="butActionRefused" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a>';
|
||||
|
||||
$langs->load("bills");
|
||||
$langs->load("orders");
|
||||
|
||||
if (! empty($conf->commande->enabled))
|
||||
{
|
||||
if($orders2invoice > 0) print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$object->id.'">'.$langs->trans("CreateInvoiceForThisCustomer").'</a>';
|
||||
else print '<a class="butActionRefused" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a>';
|
||||
}
|
||||
|
||||
if ($object->client != 0) print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a>';
|
||||
else print '<a class="butActionRefused" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a>';
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -234,6 +234,7 @@ if ($result)
|
||||
// If the user can view prospects other than his'
|
||||
if ($user->rights->societe->client->voir || $socid)
|
||||
{
|
||||
$langs->load("commercial");
|
||||
$moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
|
||||
$moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user);
|
||||
$moreforfilter.=' ';
|
||||
|
||||
@ -250,7 +250,8 @@ if ($resql)
|
||||
// If the user can view prospects other than his'
|
||||
if ($user->rights->societe->client->voir || $socid)
|
||||
{
|
||||
$moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
|
||||
$langs->load("commercial");
|
||||
$moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
|
||||
$moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user);
|
||||
$moreforfilter.=' ';
|
||||
}
|
||||
@ -329,16 +330,16 @@ if ($resql)
|
||||
print '<td>';
|
||||
print $companystatic->getNomUrl(1,'customer');
|
||||
print ' <a href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$companystatic->id.'">';
|
||||
|
||||
|
||||
// If module invoices enabled and user with invoice creation permissions
|
||||
if (! empty($conf->facture->enabled))
|
||||
{
|
||||
if ($user->rights->facture->creer)
|
||||
{
|
||||
|
||||
|
||||
if (($objp->fk_statut > 0 && $objp->fk_statut < 3) || ($objp->fk_statut == 3 && $objp->facturee == 0))
|
||||
{
|
||||
|
||||
|
||||
print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->nom,'object_bill').'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,7 +256,8 @@ if ($resql)
|
||||
$moreforfilter='';
|
||||
if ($user->rights->societe->client->voir || $socid)
|
||||
{
|
||||
$moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
|
||||
$langs->load("commercial");
|
||||
$moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
|
||||
$moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user);
|
||||
$moreforfilter.=' ';
|
||||
}
|
||||
|
||||
@ -68,6 +68,8 @@ if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='ye
|
||||
|
||||
$datepaye = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
|
||||
$paiement_id = 0;
|
||||
$totalpaiement = 0;
|
||||
$atleastonepaymentnotnull = 0;
|
||||
|
||||
// Verifie si des paiements sont superieurs au montant facture
|
||||
foreach ($_POST as $key => $value)
|
||||
@ -77,6 +79,7 @@ if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='ye
|
||||
$cursorfacid = substr($key,7);
|
||||
$amounts[$cursorfacid] = price2num(trim($_POST[$key]));
|
||||
$totalpaiement = $totalpaiement + $amounts[$cursorfacid];
|
||||
if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
|
||||
$tmpfacture=new Facture($db);
|
||||
$tmpfacture->fetch($cursorfacid);
|
||||
$amountsresttopay[$cursorfacid]=price2num($tmpfacture->total_ttc-$tmpfacture->getSommePaiement());
|
||||
@ -108,7 +111,7 @@ if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='ye
|
||||
}
|
||||
}
|
||||
|
||||
if ($totalpaiement == 0)
|
||||
if (empty($totalpaiement) && empty($atleastonepaymentnotnull))
|
||||
{
|
||||
$fiche_erreur_message = '<div class="error">'.$langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')).'</div>';
|
||||
$error++;
|
||||
@ -154,8 +157,8 @@ if ($action == 'confirm_paiement' && $confirm == 'yes')
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0));
|
||||
if ($paiement_id < 0)
|
||||
$paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0));
|
||||
if ($paiement_id < 0)
|
||||
{
|
||||
$errmsg=$paiement->error;
|
||||
$error++;
|
||||
|
||||
@ -137,17 +137,22 @@ class Paiement extends CommonObject
|
||||
|
||||
// Clean parameters
|
||||
$totalamount = 0;
|
||||
$atleastonepaymentnotnull = 0;
|
||||
foreach ($this->amounts as $key => $value) // How payment is dispatch
|
||||
{
|
||||
$newvalue = price2num($value,'MT');
|
||||
$this->amounts[$key] = $newvalue;
|
||||
$totalamount += $newvalue;
|
||||
if (! empty($newvalue)) $atleastonepaymentnotnull++;
|
||||
}
|
||||
$totalamount = price2num($totalamount);
|
||||
|
||||
// Check parameters
|
||||
if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
|
||||
|
||||
if (empty($totalamount) && empty($atleastonepaymentnotnull)) // We accept negative amounts for withdraw reject but not empty arrays
|
||||
{
|
||||
$this->error='TotalAmountEmpty';
|
||||
return -1;
|
||||
}
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
@ -506,7 +506,7 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++)
|
||||
print '<td align="right"> ';
|
||||
if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0)
|
||||
{
|
||||
print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.'">'.price(price2num($decaiss_ttc[$case],'MT')).'</a>';
|
||||
print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta?'&modecompta='.$modecompta:'').'">'.price(price2num($decaiss_ttc[$case],'MT')).'</a>';
|
||||
if (! isset($totsorties[$annee])) $totsorties[$annee]=0;
|
||||
$totsorties[$annee]+=$decaiss_ttc[$case];
|
||||
}
|
||||
@ -515,7 +515,7 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++)
|
||||
print '<td align="right"> ';
|
||||
if (isset($encaiss_ttc[$case]) && $encaiss_ttc[$case] != 0)
|
||||
{
|
||||
print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.'">'.price(price2num($encaiss_ttc[$case],'MT')).'</a>';
|
||||
print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta?'&modecompta='.$modecompta:'').'">'.price(price2num($encaiss_ttc[$case],'MT')).'</a>';
|
||||
if (! isset($totentrees[$annee])) $totentrees[$annee]=0;
|
||||
$totentrees[$annee]+=$encaiss_ttc[$case];
|
||||
}
|
||||
|
||||
@ -2732,12 +2732,12 @@ class Form
|
||||
if ($filter) $newfilter.=' AND ('.$filter.')';
|
||||
$nbqualifiedlines=$this->select_remises($selected,$htmlname,$newfilter,$socid,$maxvalue);
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print '<td nowrap="nowrap">';
|
||||
if ($nbqualifiedlines > 0)
|
||||
{
|
||||
print ' <input type="submit" class="button" value="'.$langs->trans("UseLine").'"';
|
||||
if ($filter && $filter != "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')") print '" title="'.$langs->trans("UseCreditNoteInInvoicePayment");
|
||||
print '">';
|
||||
print ' <input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("UseLine")).'"';
|
||||
if ($filter && $filter != "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')") print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"';
|
||||
print '>';
|
||||
}
|
||||
if ($more) print $more;
|
||||
print '</td>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user