NEW : convert exceiss received to reduc

This commit is contained in:
gauthier 2016-11-24 15:48:04 +01:00
parent ae36daefbe
commit 480b08bd0b
3 changed files with 64 additions and 15 deletions

View File

@ -369,6 +369,15 @@ if ($socid > 0)
print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1); print preg_replace('/\(DEPOSIT\)/',$langs->trans("InvoiceDeposit"),$obj->description).' '.$facturestatic->getNomURl(1);
print '</td>'; print '</td>';
} }
elseif (preg_match('/\(EXCESS RECEIVED\)/',$obj->description))
{
print '<td class="nowrap">';
$facturestatic->id=$obj->fk_facture_source;
$facturestatic->ref=$obj->ref;
$facturestatic->type=$obj->type;
print preg_replace('/\(EXCESS RECEIVED\)/',$langs->trans("Invoice"),$obj->description).' '.$facturestatic->getNomURl(1);
print '</td>';
}
else else
{ {
print '<td>'; print '<td>';

View File

@ -579,7 +579,7 @@ if (empty($reshook))
$canconvert=0; $canconvert=0;
if ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 1 && empty($discountcheck->id)) $canconvert=1; // we can convert deposit into discount if deposit is payed completely and not already converted (see real condition into condition used to show button converttoreduc) if ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 1 && empty($discountcheck->id)) $canconvert=1; // we can convert deposit into discount if deposit is payed completely and not already converted (see real condition into condition used to show button converttoreduc)
if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->paye == 0 && empty($discountcheck->id)) $canconvert=1; // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc) if (($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_STANDARD) && $object->paye == 0 && empty($discountcheck->id)) $canconvert=1; // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc)
if ($canconvert) if ($canconvert)
{ {
$db->begin(); $db->begin();
@ -596,13 +596,15 @@ if (empty($reshook))
$i ++; $i ++;
} }
} }
//var_dump($amount_ht, $amount_tva, $amount_ttc);exit;
// Insert one discount by VAT rate category // Insert one discount by VAT rate category
$discount = new DiscountAbsolute($db); $discount = new DiscountAbsolute($db);
if ($object->type == Facture::TYPE_CREDIT_NOTE) if ($object->type == Facture::TYPE_CREDIT_NOTE)
$discount->description = '(CREDIT_NOTE)'; $discount->description = '(CREDIT_NOTE)';
elseif ($object->type == Facture::TYPE_DEPOSIT) elseif ($object->type == Facture::TYPE_DEPOSIT)
$discount->description = '(DEPOSIT)'; $discount->description = '(DEPOSIT)';
elseif ($object->type == Facture::TYPE_STANDARD)
$discount->description = '(EXCESS RECEIVED)';
else { else {
setEventMessages($langs->trans('CantConvertToReducAnInvoiceOfThisType'), null, 'errors'); setEventMessages($langs->trans('CantConvertToReducAnInvoiceOfThisType'), null, 'errors');
} }
@ -611,13 +613,22 @@ if (empty($reshook))
$discount->fk_facture_source = $object->id; $discount->fk_facture_source = $object->id;
$error = 0; $error = 0;
foreach ($amount_ht as $tva_tx => $xxx) if ($object->type == Facture::TYPE_STANDARD) {
{
$discount->amount_ht = abs($amount_ht[$tva_tx]); // If we're on a standard invoice, we have to get excess received to create it in TTC wuthout VAT
$discount->amount_tva = abs($amount_tva[$tva_tx]);
$discount->amount_ttc = abs($amount_ttc[$tva_tx]); $sql = 'SELECT SUM(pf.amount) as total_paiements
$discount->tva_tx = abs($tva_tx); FROM llx_c_paiement as c, llx_paiement_facture as pf, llx_paiement as p
WHERE pf.fk_facture = 10 AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid ORDER BY p.datep, p.tms';
$resql = $db->query($sql);
$res = $db->fetch_object($resql);
$total_paiements = $res->total_paiements;
$discount->amount_ht = $discount->amount_ttc = $total_paiements - $object->total_ttc;
$discount->amount_tva = 0;
$discount->tva_tx = 0;
$result = $discount->create($user); $result = $discount->create($user);
if ($result < 0) if ($result < 0)
@ -625,8 +636,25 @@ if (empty($reshook))
$error++; $error++;
break; break;
} }
} else {
foreach ($amount_ht as $tva_tx => $xxx)
{
$discount->amount_ht = abs($amount_ht[$tva_tx]);
$discount->amount_tva = abs($amount_tva[$tva_tx]);
$discount->amount_ttc = abs($amount_ttc[$tva_tx]);
$discount->tva_tx = abs($tva_tx);
$result = $discount->create($user);
if ($result < 0)
{
$error++;
break;
}
}
} }
if (empty($error)) if (empty($error))
{ {
// Classe facture // Classe facture
@ -2587,7 +2615,10 @@ else if ($id > 0 || ! empty($ref))
// Confirmation de la conversion de l'avoir en reduc // Confirmation de la conversion de l'avoir en reduc
if ($action == 'converttoreduc') { if ($action == 'converttoreduc') {
$text = $langs->trans('ConfirmConvertToReduc'); if($object->type == 0) $type_fac = 'ExcessReceived';
elseif($object->type == 2) $type_fac = 'CreditNote';
elseif($object->type == 3) $type_fac = 'Deposit';
$text = $langs->trans('ConfirmConvertToReduc', strtolower($langs->transnoentities($type_fac)));
$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('ConvertToReduc'), $text, 'confirm_converttoreduc', '', "yes", 2); $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('ConvertToReduc'), $text, 'confirm_converttoreduc', '', "yes", 2);
} }
@ -2829,7 +2860,10 @@ else if ($id > 0 || ! empty($ref))
$discount = new DiscountAbsolute($db); $discount = new DiscountAbsolute($db);
$result = $discount->fetch(0, $object->id); $result = $discount->fetch(0, $object->id);
if ($result > 0) { if ($result > 0) {
$morehtmlref = ' (' . $langs->trans("CreditNoteConvertedIntoDiscount", $discount->getNomUrl(1, 'discount')) . ')'; if($object->type == 0) $type_fac = 'ExcessReceived';
elseif($object->type == 2) $type_fac = 'CreditNote';
elseif($object->type == 3) $type_fac = 'Deposit';
$morehtmlref = ' (' . $langs->trans("CreditNoteConvertedIntoDiscount", strtolower($langs->transnoentities($type_fac)), $discount->getNomUrl(1, 'discount')) . ')';
} }
if ($result < 0) { if ($result < 0) {
dol_print_error('', $discount->error); dol_print_error('', $discount->error);
@ -3205,6 +3239,7 @@ else if ($id > 0 || ! empty($ref))
print $langs->trans('RemainderToPay'); print $langs->trans('RemainderToPay');
else else
print $langs->trans('ExcessReceived'); print $langs->trans('ExcessReceived');
print ' :</td>'; print ' :</td>';
print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>' . price($resteapayeraffiche) . '</b></td>'; print '<td align="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>' . price($resteapayeraffiche) . '</b></td>';
print '<td class="nowrap">&nbsp;</td></tr>'; print '<td class="nowrap">&nbsp;</td></tr>';
@ -3688,7 +3723,7 @@ else if ($id > 0 || ! empty($ref))
} }
// Reverse back money or convert to reduction // Reverse back money or convert to reduction
if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT) { if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_STANDARD) {
// For credit note only // For credit note only
if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement)
{ {
@ -3702,6 +3737,11 @@ else if ($id > 0 || ! empty($ref))
} }
} }
// For standard invoice with excess received
if ($object->type == Facture::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) < 0 && $user->rights->facture->creer && empty($discount->id))
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&amp;action=converttoreduc">'.$langs->trans('ConvertToReduc').'</a></div>';
}
// For credit note // For credit note
if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0) { if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '&amp;action=converttoreduc">' . $langs->trans('ConvertToReduc') . '</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '&amp;action=converttoreduc">' . $langs->trans('ConvertToReduc') . '</a></div>';

View File

@ -61,7 +61,7 @@ PaymentsBack=Payments back
PaidBack=Paid back PaidBack=Paid back
DeletePayment=Delete payment DeletePayment=Delete payment
ConfirmDeletePayment=Are you sure you want to delete this payment ? ConfirmDeletePayment=Are you sure you want to delete this payment ?
ConfirmConvertToReduc=Do you want to convert this credit note or deposit into an absolute discount ?<br>The amount will so be saved among all discounts and could be used as a discount for a current or a future invoice for this customer. ConfirmConvertToReduc=Do you want to convert this %s into an absolute discount ?<br>The amount will so be saved among all discounts and could be used as a discount for a current or a future invoice for this customer.
SupplierPayments=Suppliers payments SupplierPayments=Suppliers payments
ReceivedPayments=Received payments ReceivedPayments=Received payments
ReceivedCustomersPayments=Payments received from customers ReceivedCustomersPayments=Payments received from customers
@ -386,7 +386,7 @@ ChequeDeposits=Checks deposits
Cheques=Checks Cheques=Checks
DepositId=Id deposit DepositId=Id deposit
NbCheque=Number of checks NbCheque=Number of checks
CreditNoteConvertedIntoDiscount=This credit note or deposit invoice has been converted into %s CreditNoteConvertedIntoDiscount=This %s has been converted into %s
UsBillingContactAsIncoiveRecipientIfExist=Use customer billing contact address instead of third party address as recipient for invoices UsBillingContactAsIncoiveRecipientIfExist=Use customer billing contact address instead of third party address as recipient for invoices
ShowUnpaidAll=Show all unpaid invoices ShowUnpaidAll=Show all unpaid invoices
ShowUnpaidLateOnly=Show late unpaid invoices only ShowUnpaidLateOnly=Show late unpaid invoices only