From 7f0a01936edc502b82370825a054de184714c41b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 Nov 2014 20:41:52 +0100 Subject: [PATCH] Fix a very old bug of conflicth into decrease stock when using point of sale, not compatible with option defined into stock module. --- htdocs/cashdesk/admin/cashdesk.php | 31 +++++++++++++++++++------ htdocs/cashdesk/index.php | 4 ++-- htdocs/cashdesk/index_verif.php | 16 ++++++------- htdocs/cashdesk/tpl/menu.tpl.php | 2 +- htdocs/langs/en_US/admin.lang | 7 ++++-- htdocs/product/stock/card.php | 36 +++++++++++++++++++++++------- 6 files changed, 68 insertions(+), 28 deletions(-) diff --git a/htdocs/cashdesk/admin/cashdesk.php b/htdocs/cashdesk/admin/cashdesk.php index 277dc81820b..46e7611b6ed 100644 --- a/htdocs/cashdesk/admin/cashdesk.php +++ b/htdocs/cashdesk/admin/cashdesk.php @@ -53,11 +53,12 @@ if (GETPOST('action','alpha') == 'set') /*if (GETPOST("CASHDESK_ID_BANKACCOUNT") < 0) $_POST["CASHDESK_ID_BANKACCOUNT"]=''; if (GETPOST("CASHDESK_ID_WAREHOUSE") < 0) $_POST["CASHDESK_ID_WAREHOUSE"]='';*/ - $res = dolibarr_set_const($db,"CASHDESK_ID_THIRDPARTY",GETPOST('socid','int'),'chaine',0,'',$conf->entity); - $res = dolibarr_set_const($db,"CASHDESK_ID_BANKACCOUNT_CASH",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'),'chaine',0,'',$conf->entity); - $res = dolibarr_set_const($db,"CASHDESK_ID_BANKACCOUNT_CB",GETPOST('CASHDESK_ID_BANKACCOUNT_CB','alpha'),'chaine',0,'',$conf->entity); - $res = dolibarr_set_const($db,"CASHDESK_ID_WAREHOUSE",GETPOST('CASHDESK_ID_WAREHOUSE','alpha'),'chaine',0,'',$conf->entity); + $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); + $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); dol_syslog("admin/cashdesk: level ".GETPOST('level','alpha')); @@ -129,9 +130,25 @@ if (! empty($conf->banque->enabled)) if (! empty($conf->stock->enabled)) { $var=!$var; - print ''.$langs->trans("CashDeskIdWareHouse").''; + print ''.$langs->trans("CashDeskDoNotDecreaseStock").''; // Force warehouse (this is not a default value) print ''; - print $formproduct->selectWarehouses($conf->global->CASHDESK_ID_WAREHOUSE,'CASHDESK_ID_WAREHOUSE','',1); + print $form->selectyesno('CASHDESK_NO_DECREASE_STOCK',$conf->global->CASHDESK_NO_DECREASE_STOCK,1); + print ''; + + $disabled=$conf->global->CASHDESK_NO_DECREASE_STOCK; + + $var=!$var; + print ''.$langs->trans("CashDeskIdWareHouse").''; // Force warehouse (this is not a default value) + print ''; + if (! $disabled) + { + print $formproduct->selectWarehouses($conf->global->CASHDESK_ID_WAREHOUSE,'CASHDESK_ID_WAREHOUSE','',1,$disabled); + print ' ('.$langs->trans("Create").')'; + } + else + { + print $langs->trans("StockDecreaseForPointOfSaleDisabled"); + } print ''; } diff --git a/htdocs/cashdesk/index.php b/htdocs/cashdesk/index.php index a2eb40f2932..26dd0f941ef 100644 --- a/htdocs/cashdesk/index.php +++ b/htdocs/cashdesk/index.php @@ -99,14 +99,14 @@ print $form->select_company(GETPOST('socid','int')?GETPOST('socid','int'):$conf- print ''; print "\n"; -if (! empty($conf->stock->enabled)) +if (! empty($conf->stock->enabled) && empty($conf->global->CASHDESK_NO_DECREASE_STOCK)) { $langs->load("stocks"); print ""; print ''.$langs->trans("Warehouse").''; print ''; $disabled=0; - if (! empty($conf->global->CASHDESK_ID_WAREHOUSE)) $disabled=1; // If a particular stock is defined, we disable choice + if ($conf->global->CASHDESK_ID_WAREHOUSE > 0) $disabled=1; // If a particular stock is defined, we disable choice print $formproduct->selectWarehouses((GETPOST('warehouseid')?GETPOST('warehouseid'):(empty($conf->global->CASHDESK_ID_WAREHOUSE)?'ifone':$conf->global->CASHDESK_ID_WAREHOUSE)),'warehouseid','',!$disabled,$disabled); //print ''; print ''; diff --git a/htdocs/cashdesk/index_verif.php b/htdocs/cashdesk/index_verif.php index c96b4f2b6f1..3079de5e003 100644 --- a/htdocs/cashdesk/index_verif.php +++ b/htdocs/cashdesk/index_verif.php @@ -36,11 +36,11 @@ $langs->load("cashdesk"); $username = GETPOST("txtUsername"); $password = GETPOST("pwdPassword"); -$thirdpartyid = (GETPOST('socid','int')!='')?GETPOST('socid','int'):$conf->global->CASHDESK_ID_THIRDPARTY; -$warehouseid = (GETPOST("warehouseid")!='')?GETPOST("warehouseid"):$conf->global->CASHDESK_ID_WAREHOUSE; -$bankid_cash = (GETPOST("CASHDESK_ID_BANKACCOUNT_CASH")!='')?GETPOST("CASHDESK_ID_BANKACCOUNT_CASH"):$conf->global->CASHDESK_ID_BANKACCOUNT_CASH; -$bankid_cheque = (GETPOST("CASHDESK_ID_BANKACCOUNT_CHEQUE")!='')?GETPOST("CASHDESK_ID_BANKACCOUNT_CHEQUE"):$conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE; -$bankid_cb = (GETPOST("CASHDESK_ID_BANKACCOUNT_CB")!='')?GETPOST("CASHDESK_ID_BANKACCOUNT_CB"):$conf->global->CASHDESK_ID_BANKACCOUNT_CB; +$thirdpartyid = (GETPOST('socid','int') > 0)?GETPOST('socid','int'):$conf->global->CASHDESK_ID_THIRDPARTY; +$warehouseid = (GETPOST("warehouseid") > 0)?GETPOST("warehouseid",'int'):$conf->global->CASHDESK_ID_WAREHOUSE; +$bankid_cash = (GETPOST("CASHDESK_ID_BANKACCOUNT_CASH") > 0)?GETPOST("CASHDESK_ID_BANKACCOUNT_CASH",'int'):$conf->global->CASHDESK_ID_BANKACCOUNT_CASH; +$bankid_cheque = (GETPOST("CASHDESK_ID_BANKACCOUNT_CHEQUE") > 0)?GETPOST("CASHDESK_ID_BANKACCOUNT_CHEQUE",'int'):$conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE; +$bankid_cb = (GETPOST("CASHDESK_ID_BANKACCOUNT_CB") > 0)?GETPOST("CASHDESK_ID_BANKACCOUNT_CB",'int'):$conf->global->CASHDESK_ID_BANKACCOUNT_CB; // Check username if (empty($username)) @@ -58,15 +58,15 @@ if (! ($thirdpartyid > 0)) } // If we setup stock module to ask movement on invoices, we must not allow access if required setup not finished. -if (! empty($conf->stock->enabled) && $conf->global->STOCK_CALCULATE_ON_BILL && ! ($warehouseid > 0)) +if (! empty($conf->stock->enabled) && empty($conf->global->CASHDESK_NO_DECREASE_STOCK) && ! ($warehouseid > 0)) { - $retour=$langs->trans("CashDeskSetupStock"); + $retour=$langs->trans("CashDeskYouDidNotDisableStockDecease"); header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid.'&bankid_cash='.$bankid_cash.'&bankid_cheque='.$bankid_cheque.'&bankid_cb='.$bankid_cb); exit; } // If stock decrease on bill validation, check user has stock edit permissions -if (! empty($conf->stock->enabled) && $conf->global->STOCK_CALCULATE_ON_BILL && ! empty($username)) +if (! empty($conf->stock->enabled) && empty($conf->global->CASHDESK_NO_DECREASE_STOCK) && ! empty($username)) { $testuser=new User($db); $testuser->fetch(0,$username); diff --git a/htdocs/cashdesk/tpl/menu.tpl.php b/htdocs/cashdesk/tpl/menu.tpl.php index 4ee52ce0da6..ce38bb7d7e8 100644 --- a/htdocs/cashdesk/tpl/menu.tpl.php +++ b/htdocs/cashdesk/tpl/menu.tpl.php @@ -72,7 +72,7 @@ print $langs->trans("CashDeskThirdParty").': '.$companyLink.'
'; /*print $langs->trans("CashDeskBankCash").': '.$bankcashLink.'
'; print $langs->trans("CashDeskBankCB").': '.$bankcbLink.'
'; print $langs->trans("CashDeskBankCheque").': '.$bankchequeLink.'
';*/ -if (!empty($_SESSION["CASHDESK_ID_WAREHOUSE"]) && ! empty($conf->stock->enabled)) +if (!empty($_SESSION["CASHDESK_ID_WAREHOUSE"]) && ! empty($conf->stock->enabled) && empty($conf->global->CASHDESK_NO_DECREASE_STOCK)) { print $langs->trans("CashDeskWarehouse").': '.$warehouseLink; } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 9a284748de1..3e20d071cee 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1483,11 +1483,14 @@ ClickToDialDesc=This module allows to add an icon after phone numbers. A click o ##### Point Of Sales (CashDesk) ##### CashDesk=Point of sales CashDeskSetup=Point of sales module setup -CashDeskThirdPartyForSell=Generic third party to use for sells +CashDeskThirdPartyForSell=Default generic third party to use for sells CashDeskBankAccountForSell=Default account to use to receive cash payments CashDeskBankAccountForCheque= Default account to use to receive payments by cheque CashDeskBankAccountForCB= Default account to use to receive payments by credit cards -CashDeskIdWareHouse=Warehouse to use for sells +CashDeskDoNotDecreaseStock=Disable stock decrease when a sell is done from Point of Sale +CashDeskIdWareHouse=Force and restrict warehouse to use for stock decrease +StockDecreaseForPointOfSaleDisabled=Stock decrease from Point Of Sale disabled +CashDeskYouDidNotDisableStockDecease=You did not disable stock decrease when making a sell from Point Of Sale. So a warehouse is required. ##### Bookmark ##### BookmarkSetup=Bookmark module setup BookmarkDesc=This module allows you to manage bookmarks. You can also add shortcuts to any Dolibarr pages or externale web sites on your left menu. diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index 051a0575aaa..4c8ac74c463 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -45,6 +45,8 @@ $id = GETPOST("id",'int'); if (! $sortfield) $sortfield="p.ref"; if (! $sortorder) $sortorder="DESC"; +$backtopage=GETPOST("backtopage"); + // Security check $result=restrictedArea($user,'stock'); @@ -71,16 +73,29 @@ if ($action == 'add' && $user->rights->stock->creer) $object->town = GETPOST("town"); $object->country_id = GETPOST("country_id"); - if (! empty($object->libelle)) { + if (! empty($object->libelle)) + { $id = $object->create($user); if ($id > 0) { - header("Location: card.php?id=".$id); - exit; + setEventMessage($langs->trans("RecordSaved")); + + if (! empty($backtopage)) + { + header("Location: ".$backtopage); + exit; + } + else + { + header("Location: card.php?id=".$id); + exit; + } + } + else + { + $action = 'create'; + setEventMessage($object->error, 'errors'); } - - $action = 'create'; - setEventMessage($object->error, 'errors'); } else { setEventMessage($langs->trans("ErrorWarehouseRefRequired"), 'errors'); @@ -164,7 +179,10 @@ if ($action == 'create') print "
\n"; print ''; print ''; - + print ''; + + dol_fiche_head(); + print ''; // Ref @@ -206,7 +224,9 @@ if ($action == 'create') print '
'; - print '

'; + dol_fiche_end(); + + print '
'; print '
'; }