Use any dolibarr enabled paiement mode

This commit is contained in:
David Beniamine 2019-03-15 12:07:33 +01:00
parent 48a0c447b4
commit 833da30af1
No known key found for this signature in database
GPG Key ID: DFC3C8C672850E10
6 changed files with 126 additions and 50 deletions

View File

@ -55,4 +55,6 @@ Numberspad=Numbers Pad
BillsCoinsPad=Bills and Coins Pad
DolistorePosCategory=TakePOS modules and other POS solutions for Dolibarr
TakeposNeedsCategories=TakePOS needs product categories to work
OrderNotes=Order Notes
OrderNotes=Order Notes
CashDeskBankAccountFor=Account used for payments in
NoPaimementModesDefined=No paiment mode defined in TakePOS configuration

View File

@ -49,3 +49,5 @@ AmountAtEndOfPeriod=Montant en fin de période (jour, mois ou année)
TheoricalAmount=Montant théorique
RealAmount=Montant réel
CashFenceDone=Clôture de caisse faite pour la période
CashDeskBankAccountFor=Compte utilisé pour les paiements en
NoPaimementModesDefined=Pas de mode de paiement défini dans la configuration de TakePOS

View File

@ -41,19 +41,30 @@ if (!$user->admin) accessforbidden();
$langs->loadLangs(array("admin", "cashdesk"));
global $db;
$sql="SELECT code, libelle FROM ".MAIN_DB_PREFIX."c_paiement WHERE active=1 ORDER BY libelle";
$resql = $db->query($sql);
$paiements = array();
if($resql){
while ($obj = $db->fetch_object($resql)){
array_push($paiements, $obj);
}
}
/*
* Actions
*/
if (GETPOST('action', 'alpha') == 'set')
{
$db->begin();
if (GETPOST('socid', 'int') < 0) $_POST["socid"]='';
$res = dolibarr_set_const($db, "CASHDESK_ID_THIRDPARTY", (GETPOST('socid', 'int') > 0 ? GETPOST('socid', 'int') : ''), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "CASHDESK_ID_BANKACCOUNT_CASH", (GETPOST('CASHDESK_ID_BANKACCOUNT_CASH', 'alpha') > 0 ? GETPOST('CASHDESK_ID_BANKACCOUNT_CASH', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "CASHDESK_ID_BANKACCOUNT_CHEQUE", (GETPOST('CASHDESK_ID_BANKACCOUNT_CHEQUE', 'alpha') > 0 ? GETPOST('CASHDESK_ID_BANKACCOUNT_CHEQUE', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "CASHDESK_ID_BANKACCOUNT_CB", (GETPOST('CASHDESK_ID_BANKACCOUNT_CB', 'alpha') > 0 ? GETPOST('CASHDESK_ID_BANKACCOUNT_CB', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
foreach($paiements as $modep){
$name="CASHDESK_ID_BANKACCOUNT_".$modep->code;
$res = dolibarr_set_const($db, $name, (GETPOST($name, 'alpha') > 0 ? GETPOST($name, 'alpha') : ''), 'chaine', 0, '', $conf->entity);
}
$res = dolibarr_set_const($db, "CASHDESK_ID_WAREHOUSE", (GETPOST('CASHDESK_ID_WAREHOUSE', 'alpha') > 0 ? GETPOST('CASHDESK_ID_WAREHOUSE', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "CASHDESK_NO_DECREASE_STOCK", GETPOST('CASHDESK_NO_DECREASE_STOCK', 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "CASHDESK_SERVICES", GETPOST('CASHDESK_SERVICES', 'alpha'), 'chaine', 0, '', $conf->entity);
@ -225,27 +236,19 @@ print "</tr>\n";
print '<tr class="oddeven"><td width=\"50%\">'.$langs->trans("CashDeskThirdPartyForSell").'</td>';
print '<td colspan="2">';
print $form->select_company($conf->global->CASHDESK_ID_THIRDPARTY, 'socid', 's.client in (1,3) AND s.status = 1', 1, 0, 0, array(), 0);
print $form->select_company($conf->global->CASHDESK_ID_THIRDPARTY, 'socid', 's.client in (1, 3) AND s.status = 1', 1, 0, 0, array(), 0);
print '</td></tr>';
if (! empty($conf->banque->enabled))
{
print '<tr class="oddeven"><td>'.$langs->trans("CashDeskBankAccountForSell").'</td>';
print '<td colspan="2">';
$form->select_comptes($conf->global->CASHDESK_ID_BANKACCOUNT_CASH, 'CASHDESK_ID_BANKACCOUNT_CASH', 0, "courant=2", 1);
print '</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans("CashDeskBankAccountForCheque").'</td>';
print '<td colspan="2">';
$form->select_comptes($conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE, 'CASHDESK_ID_BANKACCOUNT_CHEQUE', 0, "courant=1", 1);
print '</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans("CashDeskBankAccountForCB").'</td>';
print '<td colspan="2">';
$form->select_comptes($conf->global->CASHDESK_ID_BANKACCOUNT_CB, 'CASHDESK_ID_BANKACCOUNT_CB', 0, "courant=1", 1);
print '</td></tr>';
foreach($paiements as $modep){
$name="CASHDESK_ID_BANKACCOUNT_".$modep->code;
print '<tr class="oddeven"><td>'.$langs->trans("CashDeskBankAccountFor").' '.$langs->trans($modep->libelle).'</td>';
print '<td colspan="2">';
$cour=preg_match('/^LIQ.*/', $modep->code)?2:1;
$form->select_comptes($conf->global->$name, $name, 0, "courant=$cour", 1);
print '</td></tr>';
}
}
if (! empty($conf->stock->enabled))

View File

@ -16,10 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
// if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
// if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
// if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
// if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
// if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
// if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
// if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
if (!defined('NOCSRFCHECK')) { define('NOCSRFCHECK', '1'); }
if (!defined('NOTOKENRENEWAL')) { define('NOTOKENRENEWAL', '1'); }
if (!defined('NOREQUIREMENU')) { define('NOREQUIREMENU', '1'); }
@ -40,6 +40,10 @@ $number = GETPOST('number');
$idline = GETPOST('idline');
$desc = GETPOST('desc', 'alpha');
$pay = GETPOST('pay');
$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS-".$place.")'";
$resql = $db->query($sql);
$row = $db->fetch_array($resql);
$placeid = $row[0];
$placeid = 0; // $placeid is id of invoice
@ -48,16 +52,20 @@ $ret = $invoice->fetch('', '(PROV-POS-'.$place.')');
if ($ret > 0) $placeid = $invoice->id;
// Retrieve paiementid
$sql="SELECT id FROM ".MAIN_DB_PREFIX."c_paiement WHERE code='$pay'";
$resql = $db->query($sql);
$codes = $db->fetch_array($resql);
$paiementid=$codes[0];
/*
* Actions
*/
if ($action == 'valid' && $user->rights->facture->creer)
{
if ($pay == "cash") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CASH;
elseif ($pay == "card") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CB;
elseif ($pay == "cheque") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE;
$accountname="CASHDESK_ID_BANKACCOUNT_".$pay;
$bankaccount=$conf->global->$accountname;
$now=dol_now();
$invoice = new Facture($db);
@ -72,12 +80,10 @@ if ($action == 'valid' && $user->rights->facture->creer)
$payment->bank_account = $bankaccount;
$payment->amounts[$invoice->id] = $invoice->total_ttc;
if ($pay=="cash") $payment->paiementid = 4;
elseif ($pay=="card") $payment->paiementid = 6;
elseif ($pay=="cheque") $payment->paiementid = 7;
$payment->num_payment = $invoice->ref;
$payment->paiementid=$paiementid;
$payment->num_paiement=$invoice->ref;
$payment->create($user);
$payment->create($user);
$payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', '');
$invoice->set_paid($user);

View File

@ -15,10 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Not disabled cause need to load personalized language
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1');
if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1');
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
@ -50,6 +50,16 @@ else{
top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
$langs->loadLangs(array("main", "bills", "cashdesk"));
$sql="SELECT code, libelle FROM ".MAIN_DB_PREFIX."c_paiement WHERE active=1 ORDER BY libelle";
$resql = $db->query($sql);
$paiements = array();
if($resql){
while ($obj = $db->fetch_object($resql)){
$accountname="CASHDESK_ID_BANKACCOUNT_".$obj->code;
if($conf->global->$accountname) array_push($paiements, $obj);
}
}
?>
<link rel="stylesheet" href="css/pos.css">
<script>
@ -79,10 +89,10 @@ $langs->loadLangs(array("main", "bills", "cashdesk"));
}
function Validate(payment){
parent.$("#poslines").load("invoice.php?place=<?php echo $place;?>&action=valid&pay="+payment, function() {
parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
parent.$.colorbox.close();
});
parent.$("#poslines").load("invoice.php?place=<?php echo $place;?>&action=valid&pay="+payment, function() {
parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
parent.$.colorbox.close();
});
}
</script>
@ -105,25 +115,68 @@ $langs->loadLangs(array("main", "bills", "cashdesk"));
<div style="position:absolute; top:40%; left:5%; height:55%; width:91%;">
<?php
$action_buttons = array(
array(
"function" =>"reset()",
"span" => "style='font-size: 150%;'",
"text" => "C",
),
array(
"function" => "parent.$.colorbox.close();",
"span" => "id='printtext'",
"text" => $langs->trans("GoBack"),
),
);
$numpad=$conf->global->TAKEPOS_NUMPAD;
?>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "7"; else print "10";?>);"><?php if ($numpad==0) print "7"; else print "10";?></button>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "8"; else print "20";?>);"><?php if ($numpad==0) print "8"; else print "20";?></button>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "9"; else print "50";?>);"><?php if ($numpad==0) print "9"; else print "50";?></button>
<button type="button" <?php if ($placeid==0) echo "disabled";?> class="calcbutton2" onclick="Validate('cash');"><?php echo $langs->trans("Cash"); ?></button>
<?php if (count($paiements) >0) : ?>
<button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paiements[0]->code); ?>');"><?php echo $langs->trans($paiements[0]->libelle); ?></button>
<?php else: ?>
<button type="button" class="calcbutton2"><?php echo $langs->trans("NoPaimementModesDefined");?></button>
<?php endif ?>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "4"; else print "1";?>);"><?php if ($numpad==0) print "4"; else print "1";?></button>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "5"; else print "2";?>);"><?php if ($numpad==0) print "5"; else print "2";?></button>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "6"; else print "5";?>);"><?php if ($numpad==0) print "6"; else print "5";?></button>
<button type="button" <?php if ($placeid==0) echo "disabled";?> class="calcbutton2" onclick="Validate('card');"><?php echo $langs->trans("PaymentTypeCB"); ?></button>
<?php if (count($paiements) >1) : ?>
<button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paiements[1]->code); ?>');"><?php echo $langs->trans($paiements[1]->libelle); ?></button>
<?php else: ?>
<?php
$button = array_pop($action_buttons);
?>
<button type="button" class="calcbutton2" onclick="<?php echo $button["function"];?>"><span <?php echo $button["span"];?>><?php echo $button["text"];?></span></button>
<?php endif ?>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "1"; else print "0.10";?>);"><?php if ($numpad==0) print "1"; else print "0.10";?></button>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "2"; else print "0.20";?>);"><?php if ($numpad==0) print "2"; else print "0.20";?></button>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "3"; else print "0.50";?>);"><?php if ($numpad==0) print "3"; else print "0.50";?></button>
<button type="button" <?php if ($placeid==0) echo "disabled";?> class="calcbutton2" onclick="Validate('cheque');"><?php echo $langs->trans("Cheque"); ?></button>
<?php if (count($paiements) >2) : ?>
<button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paiements[2]->code); ?>');"><?php echo $langs->trans($paiements[2]->libelle); ?></button>
<?php else: ?>
<?php
$button = array_pop($action_buttons);
?>
<button type="button" class="calcbutton2" onclick="<?php echo $button["function"];?>"><span <?php echo $button["span"];?>><?php echo $button["text"];?></span></button>
<?php endif ?>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "0"; else print "0.01";?>);"><?php if ($numpad==0) print "0"; else print "0.01";?></button>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "'000'"; else print "0.02";?>);"><?php if ($numpad==0) print "000"; else print "0.02";?></button>
<button type="button" class="calcbutton" onclick="addreceived(<?php if ($numpad==0) print "'.'"; else print "0.05";?>);"><?php if ($numpad==0) print "."; else print "0.05";?></button>
<button type="button" class="calcbutton3" onclick="reset();"><span style='font-size: 150%;'>C</span></button>
<button type="button" class="calcbutton3" onclick="parent.$.colorbox.close();"><span id="printtext"><?php echo $langs->trans("GoBack"); ?></span></button>
<?php
$i=3;
while($i < count($paiements)){
?>
<button type="button" class="calcbutton2" onclick="Validate('<?php echo $langs->trans($paiements[$i]->code); ?>');"><?php echo $langs->trans($paiements[$i]->libelle); ?></button>
<?php
$i=$i+1;
}
$class=($i==3)?"calcbutton3":"calcbutton2";
foreach($action_buttons as $button){
?>
<button type="button" class="<?php echo $class;?>" onclick="<?php echo $button["function"];?>"><span <?php echo $button["span"];?>><?php echo $button["text"];?></span></button>
<?php
}
?>
</div>
</body>

View File

@ -450,7 +450,17 @@ $( document ).ready(function() {
<?php
// TakePOS setup check
if (empty($conf->global->CASHDESK_ID_THIRDPARTY) or empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH) or empty($conf->global->CASHDESK_ID_BANKACCOUNT_CB)) {
// TODO
$sql="SELECT code,libelle FROM ".MAIN_DB_PREFIX."c_paiement WHERE active=1 ORDER BY libelle";
$resql = $db->query($sql);
$paiementsModes = array();
if($resql){
while ($obj = $db->fetch_object($resql)){
$accountname="CASHDESK_ID_BANKACCOUNT_".$obj->code;
if($conf->global->$accountname) array_push($paiementsModes, $obj);
}
}
if (empty($paiementsModes)) {
setEventMessages($langs->trans("ErrorModuleSetupNotComplete"), null, 'errors');
}
if (count($maincategories)==0) {