25if (!defined(
'NOTOKENRENEWAL')) {
26 define(
'NOTOKENRENEWAL',
'1');
28if (!defined(
'NOREQUIREMENU')) {
29 define(
'NOREQUIREMENU',
'1');
31if (!defined(
'NOREQUIREHTML')) {
32 define(
'NOREQUIREHTML',
'1');
36require
'../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
49$langs->loadLangs(array(
'main',
'bills',
'cashdesk',
'banks'));
51$action =
GETPOST(
'action',
'aZ09');
54$place = (
GETPOST(
'place',
'aZ09') ?
GETPOST(
'place',
'aZ09') :
'0');
56if (!$user->hasRight(
'takepos',
'run')) {
68if ($action ==
'confirm_applycredit' && $discountid > 0 && !empty($_POST[
'token']) && $user->hasRight(
'takepos',
'run')) {
73 $resf = $invoice->fetch($invoiceid);
76 setEventMessages($langs->trans(
'ErrorRecordNotFound'),
null,
'errors');
80 $resd = $discount->fetch($discountid);
81 if ($resd <= 0 || $discount->fk_soc != $invoice->socid) {
84 setEventMessages($langs->trans(
'ErrorRecordNotFound'),
null,
'errors');
87 if (!$error && $discount->fk_facture > 0) {
90 setEventMessages($langs->trans(
'ErrorDiscountAlreadyUsed'),
null,
'errors');
96 $remaintopay = (float)
price2num($invoice->getRemainToPay(0),
'MT');
97 $creditamount = (float)
price2num($discount->amount_ttc,
'MT');
99 if ($remaintopay <= 0) {
101 setEventMessages($langs->trans(
'TakeposNoRemainToPay'),
null,
'errors');
102 } elseif ($creditamount > $remaintopay) {
104 $remainder = (float)
price2num($creditamount - $remaintopay,
'MT');
106 $newDiscounts = $discount->splitAmount($remaintopay, $remainder);
108 $newDiscount1 = $newDiscounts[0];
110 $newDiscount2 = $newDiscounts[1];
116 $discount->fk_facture_source = 0;
117 $discount->fk_invoice_supplier_source = 0;
118 $res = $discount->delete($user);
121 setEventMessages($discount->error, $discount->errors,
'errors');
125 $newid1 = $newDiscount1->create($user);
128 setEventMessages($newDiscount1->error, $newDiscount1->errors,
'errors');
133 $newid2 = $newDiscount2->create($user);
136 setEventMessages($newDiscount2->error, $newDiscount2->errors,
'errors');
142 $result = $invoice->insert_discount($newid1);
145 setEventMessages($invoice->error, $invoice->errors,
'errors');
150 $result = $invoice->insert_discount($discountid);
153 setEventMessages($invoice->error, $invoice->errors,
'errors');
160 $successmsg = $langs->trans(
'TakeposCreditApplied');
161 dol_syslog(
'creditnote_apply.php: credit '.$discountid.
' applied to invoice '.$invoiceid, LOG_DEBUG);
172$head =
'<link rel="stylesheet" href="css/pos.css.php">';
174 $head .=
'<link rel="stylesheet" href="css/colorful.css">';
177top_htmlhead($head, $langs->trans(
'TakeposApplyAvailableCredit'), 0, 0, array(), array(
'/takepos/css/pos.css.php'));
185 $invoice->fetch($invoiceid);
194 <div style=
"padding:20px; text-align:center;">
199 parent.$(
"#poslines").load(
"invoice.php?place=" + <?php echo
"'".
dol_escape_js($place).
"'"; ?> +
"&invoiceid=<?php echo $invoiceid; ?>&token=<?php echo currentToken(); ?>",
function() {
200 parent.$.colorbox.close();
209$availableDiscounts = array();
210if ($invoice->id > 0 && $invoice->socid > 0) {
211 $sql =
'SELECT rowid, amount_ht, amount_tva, amount_ttc, description, fk_facture_source, datec, tva_tx';
212 $sql .=
' FROM '.$db->prefix().
'societe_remise_except';
213 $sql .=
' WHERE entity = '.((int)
$conf->entity);
214 $sql .=
' AND discount_type = 0';
215 $sql .=
' AND fk_soc = '.((int) $invoice->socid);
216 $sql .=
' AND fk_facture IS NULL';
217 $sql .=
' AND fk_facture_line IS NULL';
218 $sql .=
' ORDER BY datec ASC';
220 $resql = $db->query($sql);
222 while ($obj = $db->fetch_object($resql)) {
223 $availableDiscounts[] = $obj;
226 dol_print_error($db);
231if ($action ==
'applycredit' && $discountid > 0 && empty($error) && $user->hasRight(
'takepos',
'run')) {
233 $discountToConfirm->fetch($discountid);
235 $remaintopay = ($invoice->id > 0) ? (
float)
price2num($invoice->getRemainToPay(0),
'MT') : 0;
236 $creditamount = (float)
price2num($discountToConfirm->amount_ttc,
'MT');
238 $willSplit = ($creditamount > $remaintopay);
241 <div style=
"padding:20px;">
242 <h3><?php echo $langs->trans(
'TakeposConfirmApplyCredit'); ?></h3>
244 <?php
if ($remaintopay <= 0) { ?>
245 <p
class=
"error"><?php echo $langs->trans(
'TakeposNoRemainToPay'); ?></p>
246 <div style=
"text-align:center; margin-top:20px;">
247 <
button type=
"button" class=
"butActionDelete" onclick=
"parent.$.colorbox.close();">
248 <?php echo $langs->trans(
'Close'); ?>
252 <?php
if ($willSplit) {
253 $remainder =
price2num($creditamount - $remaintopay,
'MT');
254 echo
'<p class="warning">'.$langs->transnoentities(
255 'TakeposCreditSplitAuto',
256 '<strong>'.
price($remaintopay, 1, $langs, 1, -1, -1,
$conf->currency).
'</strong>',
257 '<strong>'.price($remainder, 1, $langs, 1, -1, -1,
$conf->currency).
'</strong>'
261 <
table class=
"noborder" style=
"width:100%;">
262 <tr
class=
"liste_titre">
263 <td><?php echo $langs->trans(
'TakeposCreditOrigin'); ?></td>
264 <td
class=
"right"><?php echo $langs->trans(
'TakeposCreditAmount'); ?></td>
265 <td
class=
"center"><?php echo $langs->trans(
'RemainToPay'); ?></td>
270 if ($discountToConfirm->description ==
'(CREDIT_NOTE)') {
271 echo $langs->trans(
'CreditNote');
272 } elseif ($discountToConfirm->description ==
'(DEPOSIT)') {
273 echo $langs->trans(
'Deposit');
277 if ($discountToConfirm->fk_facture_source > 0) {
279 $srcInv->fetch($discountToConfirm->fk_facture_source);
280 echo
' — '.dol_escape_htmltag($srcInv->ref);
284 <td
class=
"right"><strong><?php echo
price($creditamount, 1, $langs, 1, -1, -1,
$conf->currency); ?></strong></td>
285 <td
class=
"center"><?php echo
price($remaintopay, 1, $langs, 1, -1, -1,
$conf->currency); ?></td>
291 <form method=
"POST" action=
"creditnote_apply.php">
292 <input
type=
"hidden" name=
"token" value=
"<?php echo newToken(); ?>">
293 <input
type=
"hidden" name=
"action" value=
"confirm_applycredit">
294 <input
type=
"hidden" name=
"invoiceid" value=
"<?php echo $invoiceid; ?>">
295 <input
type=
"hidden" name=
"discountid" value=
"<?php echo $discountid; ?>">
296 <input
type=
"hidden" name=
"place" value=
"<?php echo dol_escape_htmltag($place); ?>">
298 <div style=
"text-align:center; margin-top:20px;">
300 <?php echo $langs->trans(
'Confirm'); ?>
303 <
button type=
"button" class=
"butActionDelete" onclick=
"parent.$.colorbox.close();">
304 <?php echo $langs->trans(
'Cancel'); ?>
318<div style=
"padding:15px;">
319 <h3><?php echo $langs->trans(
'TakeposSelectCreditToApply'); ?></h3>
321 <?php
if (empty($availableDiscounts)) { ?>
322 <p
class=
"opacitymedium"><?php echo $langs->trans(
'TakeposNoCreditAvailable'); ?></p>
324 <
table class=
"noborder" style=
"width:100%;">
325 <tr
class=
"liste_titre">
326 <td><?php echo $langs->trans(
'TakeposCreditOrigin'); ?></td>
327 <td
class=
"center"><?php echo $langs->trans(
'TakeposCreditDate'); ?></td>
328 <td
class=
"right"><?php echo $langs->trans(
'TakeposCreditAmount'); ?></td>
329 <td
class=
"center"><?php echo $langs->trans(
'Action'); ?></td>
331 <?php
foreach ($availableDiscounts as $disc) {
333 if ($disc->description ==
'(CREDIT_NOTE)') {
334 $originLabel = $langs->trans(
'CreditNote');
335 } elseif ($disc->description ==
'(DEPOSIT)') {
336 $originLabel = $langs->trans(
'Deposit');
337 } elseif ($disc->description ==
'(EXCESS RECEIVED)') {
338 $originLabel = $langs->trans(
'ExcessReceived');
342 if ($disc->fk_facture_source > 0) {
344 $srcInv->fetch($disc->fk_facture_source);
345 $originLabel .=
' — '.dol_escape_htmltag($srcInv->ref);
349 <td><?php echo $originLabel; ?></td>
350 <td
class=
"center"><?php echo
dol_print_date($db->jdate($disc->datec),
'day'); ?></td>
351 <td
class=
"right"><strong><?php echo
price($disc->amount_ttc, 1, $langs, 1, -1, -1,
$conf->currency); ?></strong></td>
354 $remaintopay = ($invoice->id > 0) ? (
float)
price2num($invoice->getRemainToPay(0),
'MT') : 0;
355 if ($remaintopay <= 0) {
356 echo
'<span class="opacitymedium">'.$langs->trans(
'TakeposNoRemainToPay').
'</span>';
359 <form method=
"POST" action=
"creditnote_apply.php" style=
"display:inline;">
360 <input
type=
"hidden" name=
"token" value=
"<?php echo newToken(); ?>">
361 <input
type=
"hidden" name=
"action" value=
"applycredit">
362 <input
type=
"hidden" name=
"invoiceid" value=
"<?php echo $invoiceid; ?>">
363 <input
type=
"hidden" name=
"discountid" value=
"<?php echo (int) $disc->rowid; ?>">
364 <input
type=
"hidden" name=
"place" value=
"<?php echo dol_escape_htmltag($place); ?>">
365 <
button type=
"submit" class=
"butAction" style=
"padding:4px 10px;">
366 <?php echo $langs->trans(
'TakeposApplyThisCredit'); ?>
376 <div style=
"text-align:center; margin-top:20px;">
377 <
button type=
"button" class=
"butActionDelete" onclick=
"parent.$.colorbox.close();">
378 <?php echo $langs->trans(
'Close'); ?>
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage absolute discounts.
Class to manage invoices.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
$conf db name
Only used if Module[ID]Name translation string is not found.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
treeview li table
No Email.