This commit is contained in:
Grand Philippe
2012-12-10 10:02:13 +01:00
parent 158f581f03
commit a91a96e72e
43 changed files with 1252 additions and 572 deletions

View File

@@ -42,13 +42,13 @@ $langs->load('compta');
*/
//init var
$invoice_type = GETPOST('invoice_type','int');
$amountPayment = $_POST['amountPayment'];
$amounts = $_POST['amounts']; // from text inputs : invoice amount payment (check required)
$remains = $_POST['remains']; // from dolibarr's object (no need to check)
$currentInvId = $_POST['imgClicked']; // from DOM elements : imgId (equals invoice id)
// Getting the posted keys=>values, sanitize the ones who are from text inputs
// from text inputs : total amount
$amountPayment = $amountPayment!='' ? ( is_numeric(price2num($amountPayment)) ? price2num($amountPayment) : '' ) : ''; // keep void if not a valid entry
// Clean checkamounts
@@ -62,7 +62,7 @@ foreach ($amounts as $key => $value)
foreach ($remains as $key => $value)
{
$value = price2num($value);
$remains[$key]=$value;
$remains[$key]=(($invoice_type)==2?-1:1)*$value;
if (empty($value)) unset($remains[$key]);
}

View File

@@ -2647,6 +2647,9 @@ else if ($id > 0 || ! empty($ref))
* List of payments
*/
$sign=1;
if ($object->type == 2) $sign=-1;
$nbrows=8; $nbcols=2;
if (! empty($conf->projet->enabled)) $nbrows++;
if (! empty($conf->banque->enabled)) $nbcols++;
@@ -2686,9 +2689,9 @@ else if ($id > 0 || ! empty($ref))
{
$num = $db->num_rows($result);
$i = 0;
if ($object->type != 2)
{
//if ($object->type != 2)
//{
if ($num > 0)
{
while ($i < $num)
@@ -2709,7 +2712,7 @@ else if ($id > 0 || ! empty($ref))
if ($bankaccountstatic->id) print $bankaccountstatic->getNomUrl(1,'transactions');
print '</td>';
}
print '<td align="right">'.price($objp->amount).'</td>';
print '<td align="right">'.price($sign * $objp->amount).'</td>';
print '<td>&nbsp;</td>';
print '</tr>';
$i++;
@@ -2719,7 +2722,7 @@ else if ($id > 0 || ! empty($ref))
{
print '<tr '.$bc[$var].'><td colspan="'.$nbcols.'">'.$langs->trans("None").'</td><td></td><td></td></tr>';
}
}
//}
$db->free($result);
}
else
@@ -2819,11 +2822,27 @@ else if ($id > 0 || ! empty($ref))
print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>'.price($resteapayeraffiche).'</b></td>';
print '<td nowrap="nowrap">&nbsp;</td></tr>';
}
else
else // Credit note
{
// Total already paid back
print '<tr><td colspan="'.$nbcols.'" align="right">';
print $langs->trans('AlreadyPaidBack');
print ' :</td><td align="right">'.price($sign * $totalpaye).'</td><td>&nbsp;</td></tr>';
// Billed
print '<tr><td colspan="'.$nbcols.'" align="right">'.$langs->trans("Billed").' :</td><td align="right" style="border: 1px solid;">'.price($sign * $object->total_ttc).'</td><td>&nbsp;</td></tr>';
// Remainder to pay back
print '<tr><td colspan="'.$nbcols.'" align="right">';
if ($resteapayeraffiche <= 0) print $langs->trans('RemainderToPayBack');
else print $langs->trans('ExcessPaydBack');
print ' :</td>';
print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>'.price($sign * $resteapayeraffiche).'</b></td>';
print '<td nowrap="nowrap">&nbsp;</td></tr>';
// Sold credit note
print '<tr><td colspan="'.$nbcols.'" align="right">'.$langs->trans('TotalTTC').' :</td>';
print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>'.price(abs($object->total_ttc)).'</b></td><td>&nbsp;</td></tr>';
//print '<tr><td colspan="'.$nbcols.'" align="right">'.$langs->trans('TotalTTC').' :</td>';
//print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>'.price($sign * $object->total_ttc).'</b></td><td>&nbsp;</td></tr>';
}
print '</table>';

View File

@@ -83,7 +83,7 @@ if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='ye
$tmpfacture=new Facture($db);
$tmpfacture->fetch($cursorfacid);
$amountsresttopay[$cursorfacid]=price2num($tmpfacture->total_ttc-$tmpfacture->getSommePaiement());
if ($amounts[$cursorfacid] && $amounts[$cursorfacid] > $amountsresttopay[$cursorfacid])
if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
{
$addwarning=1;
$formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
@@ -147,6 +147,16 @@ if ($action == 'confirm_paiement' && $confirm == 'yes')
$db->begin();
// Clean parameters amount if payment is for a credit note
if (GETPOST('type') == 2)
{
foreach ($amounts as $key => $value) // How payment is dispatch
{
$newvalue = price2num($value,'MT');
$amounts[$key] = -$newvalue;
}
}
// Creation of payment line
$paiement = new Paiement($db);
$paiement->datepaye = $datepaye;
@@ -157,7 +167,7 @@ if ($action == 'confirm_paiement' && $confirm == 'yes')
if (! $error)
{
$paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0));
$paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0));
if ($paiement_id < 0)
{
$errmsg=$paiement->error;
@@ -167,7 +177,9 @@ if ($action == 'confirm_paiement' && $confirm == 'yes')
if (! $error)
{
$result=$paiement->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']);
$label='(CustomerInvoicePayment)';
if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)';
$result=$paiement->addPaymentToBank($user,'payment',$label,$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']);
if ($result < 0)
{
$errmsg=$paiement->error;
@@ -227,15 +239,6 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
dol_htmloutput_errors($errmsg);
// Bouchon
if ($facture->type == 2)
{
$langs->load('other');
print $langs->trans("FeatureNotYetAvailable");
llxFooter();
exit;
}
// Initialize data for confirmation (this is used because data can be change during confirmation)
if ($action == 'add_paiement')
{
@@ -253,6 +256,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
if (! empty($conf->global->PAYPAL_BANK_ACCOUNT)) $accountid=$conf->global->PAYPAL_BANK_ACCOUNT;
$paymentnum=$facture->ref_int;
}
// Add realtime total information
if ($conf->use_javascript_ajax)
{
print "\n".'<script type="text/javascript" language="javascript">';
@@ -296,6 +301,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
var json = {};
var form = $("#payment_form");
json["invoice_type"] = $("#invoice_type").val();
json["amountPayment"] = $("#amountpayment").attr("value");
json["amounts"] = _elemToJson(form.find("input[name*=\"amount_\"]"));
json["remains"] = _elemToJson(form.find("input[name*=\"remain_\"]"));
@@ -336,7 +342,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
});
';
if (! empty($conf->global->MAIN_JS_ON_PAYMENT))
// Add user helper to input amount on invoices
if (! empty($conf->global->MAIN_JS_ON_PAYMENT) && $facture->type != 2)
{
print ' $("#payment_form").find("img").click(function() {
callForResult(jQuery(this).attr("id"));
@@ -356,7 +363,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print '<input type="hidden" name="action" value="add_paiement">';
print '<input type="hidden" name="facid" value="'.$facture->id.'">';
print '<input type="hidden" name="socid" value="'.$facture->socid.'">';
print '<input type="hidden" name="type" value="'.$facture->type.'">';
print '<input type="hidden" name="type" id="invoice_type" value="'.$facture->type.'">';
print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($facture->client->name).'">';
print '<table class="border" width="100%">';
@@ -462,17 +469,26 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$num = $db->num_rows($resql);
if ($num > 0)
{
$sign=1;
if ($facture->type == 2) $sign=-1;
$arraytitle=$langs->trans('Invoice');
if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes");
$alreadypayedlabel=$langs->trans('Received');
if ($facture->type == 2) $alreadypayedlabel=$langs->trans("PaidBack");
$remaindertopay=$langs->trans('RemainderToTake');
if ($facture->type == 2) $remaindertopay=$langs->trans("RemainderToPayBack");
$i = 0;
//print '<tr><td colspan="3">';
print '<br>';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Invoice').'</td>';
print '<td>'.$arraytitle.'</td>';
print '<td align="center">'.$langs->trans('Date').'</td>';
print '<td align="right">'.$langs->trans('AmountTTC').'</td>';
print '<td align="right">'.$langs->trans('Received').'</td>';
print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
print '<td align="right">'.$alreadypayedlabel.'</td>';
print '<td align="right">'.$remaindertopay.'</td>';
print '<td align="right">'.$langs->trans('PaymentAmount').'</td>';
print '<td align="right">&nbsp;</td>';
print "</tr>\n";
@@ -505,18 +521,18 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
// 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>';
// Price
print '<td align="right">'.price($sign * $objp->total_ttc).'</td>';
// Recu
print '<td align="right">'.price($paiement);
// Received or paid back
print '<td align="right">'.price($sign * $paiement);
if ($creditnotes) print '+'.price($creditnotes);
if ($deposits) print '+'.price($deposits);
print '</td>';
// Remain to pay
print '<td align="right">'.price($remaintopay).'</td>';
$test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits));
// Remain to take or to pay back
print '<td align="right">'.price($sign * $remaintopay).'</td>';
//$test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits));
// Amount
print '<td align="right">';
@@ -543,7 +559,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
// Warning
print '<td align="center" width="16">';
if ($amounts[$invoice->id] && $amounts[$invoice->id] > $amountsresttopay[$invoice->id])
//print "xx".$amounts[$invoice->id]."-".$amountsresttopay[$invoice->id]."<br>";
if ($amounts[$invoice->id] && (abs($amounts[$invoice->id]) > abs($amountsresttopay[$invoice->id])))
{
print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay"));
}
@@ -564,12 +581,12 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
// Print total
print '<tr class="liste_total">';
print '<td colspan="2" align="left">'.$langs->trans('TotalTTC').'</td>';
print '<td align="right"><b>'.price($total_ttc).'</b></td>';
print '<td align="right"><b>'.price($totalrecu);
print '<td align="right"><b>'.price($sign * $total_ttc).'</b></td>';
print '<td align="right"><b>'.price($sign * $totalrecu);
if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
if ($totalrecudeposits) print '+'.price($totalrecudeposits);
print '</b></td>';
print '<td align="right"><b>'.price(price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT')).'</b></td>';
print '<td align="right"><b>'.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT')).'</b></td>';
print '<td align="right" id="result" style="font-weight: bold;"></td>';
print '<td align="center">&nbsp;</td>';
print "</tr>\n";
@@ -588,15 +605,20 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
// Bouton Enregistrer
if ($action != 'add_paiement')
{
// print '<tr><td colspan="3" align="center">';
print '<center><br><input type="checkbox" checked="checked" name="closepaidinvoices"> '.$langs->trans("ClosePaidInvoicesAutomatically");
$checkboxlabel=$langs->trans("ClosePaidInvoicesAutomatically");
if ($facture->type == 2) $checkboxlabel=$langs->trans("ClosePaidCreditNotesAutomatically");
$buttontitle=$langs->trans('ToMakePayment');
if ($facture->type == 2) $buttontitle=$langs->trans('ToMakePaymentBack');
print '<center><br>';
print '<input type="checkbox" checked="checked" name="closepaidinvoices"> '.$checkboxlabel;
/*if (! empty($conf->prelevement->enabled))
{
$langs->load("withdrawals");
if (! empty($conf->global->WITHDRAW_DISABLE_AUTOCREATE_ONPAYMENTS)) print '<br>'.$langs->trans("IfInvoiceNeedOnWithdrawPaymentWontBeClosed");
}*/
print '<br><input type="submit" class="button" value="'.$langs->trans('Save').'"><br><br></center>';
// print '</td></tr>';
print '<br><input type="submit" class="button" value="'.dol_escape_htmltag($buttontitle).'"><br><br>';
print '</center>';
}

View File

@@ -121,7 +121,8 @@ class Paiement extends CommonObject
/**
* Create payment of invoices into database.
* Use this->amounts to have list of invoices for the payment
* 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
@@ -189,6 +190,9 @@ class Paiement extends CommonObject
$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();
@@ -205,7 +209,7 @@ class Paiement extends CommonObject
}
}
if ($invoice->type != 0 && $invoice->type != 1) dol_syslog("Invoice ".$facid." is not a standard nor replacement invoice. We do nothing more.");
if ($invoice->type != 0 && $invoice->type != 1 && $invoice->type != 2) dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note. 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,'','');
@@ -363,7 +367,7 @@ class Paiement extends CommonObject
/**
* A record into bank for payment with links between this bank record and invoices of payment.
* All payment properties must have been set first like after a call to create().
* All payment properties (this->amount, this->amounts, ...) must have been set first like after a call to create().
*
* @param User $user Object of user making payment
* @param string $mode 'payment', 'payment_supplier'
@@ -401,7 +405,7 @@ class Paiement extends CommonObject
$this->datepaye,
$this->paiementid, // Payment mode id or code ("CHQ or VIR for example")
$label,
$totalamount,
$totalamount, // Sign must be positive when we receive money (customer payment), negative when you give money (supplier invoice or credit note)
$this->num_paiement,
'',
$user,

View File

@@ -108,11 +108,11 @@ else
else $sql.= " AND f.fk_user_author = ".$userid;
}
// Search criteria
if ($_REQUEST["search_ref"]) $sql .=" AND p.rowid=".$_REQUEST["search_ref"];
if ($_REQUEST["search_account"]) $sql .=" AND b.fk_account=".$_REQUEST["search_account"];
if ($_REQUEST["search_paymenttype"]) $sql .=" AND c.code='".$_REQUEST["search_paymenttype"]."'";
if ($_REQUEST["search_amount"]) $sql .=" AND p.amount=".price2num($_REQUEST["search_amount"]);
if ($_REQUEST["search_company"]) $sql .=" AND s.nom LIKE '%".$db->escape($_REQUEST["search_company"])."%'";
if (GETPOST("search_ref")) $sql .=" AND p.rowid=".GETPOST("search_ref",'int');
if (GETPOST("search_account") > 0) $sql .=" AND b.fk_account=".GETPOST("search_account",'int');
if (GETPOST("search_paymenttype") > 0) $sql .=" AND c.code='".GETPOST("search_paymenttype",'int')."'";
if (GETPOST("search_amount")) $sql .=" AND p.amount=".price2num(GETPOST("search_amount"));
if (GETPOST("search_company")) $sql .=" AND s.nom LIKE '%".$db->escape(GETPOST("search_company"))."%'";
}
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit+1, $offset);

View File

@@ -65,9 +65,10 @@ if ($modecompta == 'CREANCES-DETTES')
$nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$period="$year_start - $year_end";
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
$description=$langs->trans("RulesResultDue")."<br>";
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.= $langs->trans("DepositsAreNotIncluded");
else $description.= $langs->trans("DepositsAreIncluded");
$description=$langs->trans("RulesAmountWithTaxIncluded");
$description.='<br>'.$langs->trans("RulesResultDue");
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.="<br>".$langs->trans("DepositsAreNotIncluded");
else $description.="<br>".$langs->trans("DepositsAreIncluded");
$builddate=time();
//$exportlink=$langs->trans("NotYetAvailable");
}
@@ -76,7 +77,8 @@ else {
$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
$period="$year_start - $year_end";
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year_start=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
$description=$langs->trans("RulesResultInOut");
$description=$langs->trans("RulesAmountWithTaxIncluded");
$description.='<br>'.$langs->trans("RulesResultInOut");
$builddate=time();
//$exportlink=$langs->trans("NotYetAvailable");
}
@@ -513,7 +515,8 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++)
print "</td>";
print '<td align="right">&nbsp;';
if (isset($encaiss_ttc[$case]) && $encaiss_ttc[$case] != 0)
//if (isset($encaiss_ttc[$case]) && $encaiss_ttc[$case] != 0)
if (isset($encaiss_ttc[$case]))
{
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;

View File

@@ -252,7 +252,8 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++)
}
if (! $cum[$caseprev] && $cum[$case])
{
print '<td align="right">+Inf%</td>';
//print '<td align="right">+Inf%</td>';
print '<td align="right">-</td>';
}
if (isset($cum[$caseprev]) && ! $cum[$caseprev] && ! $cum[$case])
{