Merge pull request #20766 from altairis-melina/hookinvoice
NEW add hook doaction in takepos invoice
This commit is contained in:
commit
0ccd0931ab
@ -49,6 +49,8 @@ if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
|
|||||||
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
|
||||||
|
$hookmanager->initHooks(array('takeposinvoice'));
|
||||||
|
|
||||||
global $mysoc;
|
global $mysoc;
|
||||||
|
|
||||||
@ -168,11 +170,6 @@ if ($invoice->socid > 0) {
|
|||||||
$soc->fetch(getDolGlobalString("$constforcompanyid"));
|
$soc->fetch(getDolGlobalString("$constforcompanyid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Actions
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Change the currency of invoice if it was modified
|
// Change the currency of invoice if it was modified
|
||||||
if (!empty($conf->multicurrency->enabled) && !empty($_SESSION["takeposcustomercurrency"])) {
|
if (!empty($conf->multicurrency->enabled) && !empty($_SESSION["takeposcustomercurrency"])) {
|
||||||
if ($invoice->multicurrency_code != $_SESSION["takeposcustomercurrency"]) {
|
if ($invoice->multicurrency_code != $_SESSION["takeposcustomercurrency"]) {
|
||||||
@ -180,9 +177,17 @@ if (!empty($conf->multicurrency->enabled) && !empty($_SESSION["takeposcustomercu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Actions
|
||||||
|
*/
|
||||||
|
|
||||||
// Action to record a payment on a TakePOS invoice
|
$parameters=array();
|
||||||
if ($action == 'valid' && $user->rights->facture->creer) {
|
$reshook=$hookmanager->executeHooks('doActions', $parameters, $invoice, $action); // Note that $action and $object may have been modified by some hooks
|
||||||
|
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
|
||||||
|
|
||||||
|
if (empty($reshook)) {
|
||||||
|
// Action to record a payment on a TakePOS invoice
|
||||||
|
if ($action == 'valid' && $user->rights->facture->creer) {
|
||||||
$bankaccount = 0;
|
$bankaccount = 0;
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
@ -325,9 +330,9 @@ if ($action == 'valid' && $user->rights->facture->creer) {
|
|||||||
} else {
|
} else {
|
||||||
dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
|
dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == 'creditnote' && $user->rights->facture->creer) {
|
if ($action == 'creditnote' && $user->rights->facture->creer) {
|
||||||
$creditnote = new Facture($db);
|
$creditnote = new Facture($db);
|
||||||
$creditnote->socid = $invoice->socid;
|
$creditnote->socid = $invoice->socid;
|
||||||
$creditnote->date = dol_now();
|
$creditnote->date = dol_now();
|
||||||
@ -465,9 +470,9 @@ if ($action == 'creditnote' && $user->rights->facture->creer) {
|
|||||||
} else {
|
} else {
|
||||||
$res = $creditnote->validate($user);
|
$res = $creditnote->validate($user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == 'history' || $action == 'creditnote') {
|
if ($action == 'history' || $action == 'creditnote') {
|
||||||
if ($action == 'creditnote') {
|
if ($action == 'creditnote') {
|
||||||
$placeid = $creditnote->id;
|
$placeid = $creditnote->id;
|
||||||
} else {
|
} else {
|
||||||
@ -475,9 +480,9 @@ if ($action == 'history' || $action == 'creditnote') {
|
|||||||
}
|
}
|
||||||
$invoice = new Facture($db);
|
$invoice = new Facture($db);
|
||||||
$invoice->fetch($placeid);
|
$invoice->fetch($placeid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($action == "addline" || $action == "freezone") && $placeid == 0) {
|
if (($action == "addline" || $action == "freezone") && $placeid == 0) {
|
||||||
$invoice->socid = getDolGlobalString("$constforcompanyid");
|
$invoice->socid = getDolGlobalString("$constforcompanyid");
|
||||||
$invoice->date = dol_now();
|
$invoice->date = dol_now();
|
||||||
$invoice->module_source = 'takepos';
|
$invoice->module_source = 'takepos';
|
||||||
@ -495,9 +500,9 @@ if (($action == "addline" || $action == "freezone") && $placeid == 0) {
|
|||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid = ".((int) $placeid);
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid = ".((int) $placeid);
|
||||||
$db->query($sql);
|
$db->query($sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == "addline") {
|
if ($action == "addline") {
|
||||||
$prod = new Product($db);
|
$prod = new Product($db);
|
||||||
$prod->fetch($idproduct);
|
$prod->fetch($idproduct);
|
||||||
|
|
||||||
@ -561,9 +566,9 @@ if ($action == "addline") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$invoice->fetch($placeid);
|
$invoice->fetch($placeid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == "freezone") {
|
if ($action == "freezone") {
|
||||||
$customer = new Societe($db);
|
$customer = new Societe($db);
|
||||||
$customer->fetch($invoice->socid);
|
$customer->fetch($invoice->socid);
|
||||||
|
|
||||||
@ -582,9 +587,9 @@ if ($action == "freezone") {
|
|||||||
|
|
||||||
$invoice->addline($desc, $number, 1, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', 0, 0, 0, '', 'TTC', $number, 0, -1, 0, '', 0, 0, null, '', '', 0, 100, '', null, 0);
|
$invoice->addline($desc, $number, 1, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', 0, 0, 0, '', 'TTC', $number, 0, -1, 0, '', 0, 0, null, '', '', 0, 100, '', null, 0);
|
||||||
$invoice->fetch($placeid);
|
$invoice->fetch($placeid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == "addnote") {
|
if ($action == "addnote") {
|
||||||
$desc = GETPOST('addnote', 'alpha');
|
$desc = GETPOST('addnote', 'alpha');
|
||||||
if ($idline==0) {
|
if ($idline==0) {
|
||||||
$invoice->update_note($desc, '_public');
|
$invoice->update_note($desc, '_public');
|
||||||
@ -594,9 +599,9 @@ if ($action == "addnote") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$invoice->fetch($placeid);
|
$invoice->fetch($placeid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == "deleteline") {
|
if ($action == "deleteline") {
|
||||||
if ($idline > 0 and $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
|
if ($idline > 0 and $placeid > 0) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
|
||||||
$invoice->deleteline($idline);
|
$invoice->deleteline($idline);
|
||||||
$invoice->fetch($placeid);
|
$invoice->fetch($placeid);
|
||||||
@ -613,10 +618,10 @@ if ($action == "deleteline") {
|
|||||||
header("Location: ".DOL_URL_ROOT."/takepos/invoice.php");
|
header("Location: ".DOL_URL_ROOT."/takepos/invoice.php");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action to delete or discard an invoice
|
// Action to delete or discard an invoice
|
||||||
if ($action == "delete") {
|
if ($action == "delete") {
|
||||||
// $placeid is the invoice id (it differs from place) and is defined if the place is set and the ref of invoice is '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')', so the fetch at begining of page works.
|
// $placeid is the invoice id (it differs from place) and is defined if the place is set and the ref of invoice is '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')', so the fetch at begining of page works.
|
||||||
if ($placeid > 0) {
|
if ($placeid > 0) {
|
||||||
$result = $invoice->fetch($placeid);
|
$result = $invoice->fetch($placeid);
|
||||||
@ -650,9 +655,9 @@ if ($action == "delete") {
|
|||||||
$invoice->fetch($placeid);
|
$invoice->fetch($placeid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == "updateqty") {
|
if ($action == "updateqty") {
|
||||||
foreach ($invoice->lines as $line) {
|
foreach ($invoice->lines as $line) {
|
||||||
if ($line->id == $idline) {
|
if ($line->id == $idline) {
|
||||||
if (!$user->rights->takepos->editlines || (!$user->rights->takepos->editorderedlines && $line->special_code == "4")) {
|
if (!$user->rights->takepos->editlines || (!$user->rights->takepos->editorderedlines && $line->special_code == "4")) {
|
||||||
@ -664,9 +669,9 @@ if ($action == "updateqty") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$invoice->fetch($placeid);
|
$invoice->fetch($placeid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == "updateprice") {
|
if ($action == "updateprice") {
|
||||||
$customer = new Societe($db);
|
$customer = new Societe($db);
|
||||||
$customer->fetch($invoice->socid);
|
$customer->fetch($invoice->socid);
|
||||||
|
|
||||||
@ -695,9 +700,9 @@ if ($action == "updateprice") {
|
|||||||
|
|
||||||
// Reload data
|
// Reload data
|
||||||
$invoice->fetch($placeid);
|
$invoice->fetch($placeid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == "updatereduction") {
|
if ($action == "updatereduction") {
|
||||||
$customer = new Societe($db);
|
$customer = new Societe($db);
|
||||||
$customer->fetch($invoice->socid);
|
$customer->fetch($invoice->socid);
|
||||||
|
|
||||||
@ -729,15 +734,15 @@ if ($action == "updatereduction") {
|
|||||||
|
|
||||||
// Reload data
|
// Reload data
|
||||||
$invoice->fetch($placeid);
|
$invoice->fetch($placeid);
|
||||||
} elseif ($action == 'update_reduction_global') {
|
} elseif ($action == 'update_reduction_global') {
|
||||||
foreach ($invoice->lines as $line) {
|
foreach ($invoice->lines as $line) {
|
||||||
$result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit);
|
$result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
$invoice->fetch($placeid);
|
$invoice->fetch($placeid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == "order" and $placeid != 0) {
|
if ($action == "order" and $placeid != 0) {
|
||||||
include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||||
if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") {
|
if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter" || $conf->global->TAKEPOS_PRINT_METHOD == "takeposconnector") {
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
|
||||||
@ -859,10 +864,10 @@ if ($action == "order" and $placeid != 0) {
|
|||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where special_code='3' and fk_facture=".$invoice->id; // Set as printed
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where special_code='3' and fk_facture=".$invoice->id; // Set as printed
|
||||||
$db->query($sql);
|
$db->query($sql);
|
||||||
$invoice->fetch($placeid); //Reload object after set lines as printed
|
$invoice->fetch($placeid); //Reload object after set lines as printed
|
||||||
}
|
}
|
||||||
|
|
||||||
$sectionwithinvoicelink = '';
|
$sectionwithinvoicelink = '';
|
||||||
if ($action == "valid" || $action == "history" || $action == 'creditnote') {
|
if ($action == "valid" || $action == "history" || $action == 'creditnote') {
|
||||||
$sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n";
|
$sectionwithinvoicelink .= '<!-- Section with invoice link -->'."\n";
|
||||||
$sectionwithinvoicelink .= '<span style="font-size:120%;" class="center">';
|
$sectionwithinvoicelink .= '<span style="font-size:120%;" class="center">';
|
||||||
$sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." - ";
|
$sectionwithinvoicelink .= $invoice->getNomUrl(1, '', 0, 0, '', 0, 0, -1, '_backoffice')." - ";
|
||||||
@ -901,9 +906,9 @@ if ($action == "valid" || $action == "history" || $action == 'creditnote') {
|
|||||||
if ($remaintopay <= 0 && getDolGlobalString('TAKEPOS_AUTO_PRINT_TICKETS')) {
|
if ($remaintopay <= 0 && getDolGlobalString('TAKEPOS_AUTO_PRINT_TICKETS')) {
|
||||||
$sectionwithinvoicelink .= '<script type="text/javascript">$("#buttonprint").click();</script>';
|
$sectionwithinvoicelink .= '<script type="text/javascript">$("#buttonprint").click();</script>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* View
|
* View
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user