diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 471b0216ee0..9d35e4cc683 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -60,13 +60,13 @@ $langs->load('deliveries'); $langs->load('sendings'); $langs->load('products'); if (!empty($conf->incoterm->enabled)) $langs->load('incoterm'); -if (! empty($conf->margin->enabled)) - $langs->load('margins'); +if (! empty($conf->margin->enabled)) $langs->load('margins'); $id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('orderid', 'int')); $ref = GETPOST('ref', 'alpha'); $socid = GETPOST('socid', 'int'); $action = GETPOST('action', 'alpha'); +$cancel = GETPOST('cancel', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); $lineid = GETPOST('lineid', 'int'); $origin = GETPOST('origin', 'alpha'); @@ -1765,16 +1765,12 @@ if ($action == 'create' && $user->rights->commande->creer) $formconfirm = ''; - /* - * Confirmation de la suppression de la commande - */ + // Confirmation to delete if ($action == 'delete') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 1); } - /* - * Confirmation de la validation - */ + // Confirmation of validation if ($action == 'validate') { // on verifie si l'objet est en numerotation provisoire @@ -1981,52 +1977,6 @@ if ($action == 'create' && $user->rights->commande->creer) print ''; - // Ref - /* - print ''; - print ''; - print ''; - - // Ref commande client - print ''; - print ''; - - // Third party - print '';*/ - if ($soc->outstanding_limit) { // Outstanding Bill @@ -2295,29 +2245,6 @@ if ($action == 'create' && $user->rights->commande->creer) // TODO How record was recorded OrderMode (llx_c_input_method) - // Project - /* - if (! empty($conf->projet->enabled)) - { - $langs->load('projects'); - print ''; - } - */ - // Incoterms if (!empty($conf->incoterm->enabled)) { diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index 8cbf532c89a..58fd97ab802 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -45,6 +45,7 @@ $langs->load("companies"); $langs->load("compta"); $action=GETPOST("action"); +$cancel = GETPOST('cancel', 'alpha'); // Security check if (isset($_GET["id"]) || isset($_GET["ref"])) @@ -55,69 +56,77 @@ $fieldid = isset($_GET["ref"])?'ref':'rowid'; if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'banque',$id,'bank_account&bank_account','','',$fieldid); -$account = new Account($db); +$object = new Account($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($account->table_element); +$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); + /* * Actions */ -if ($_POST["action"] == 'add') + +if ($cancel) $action=''; + +if ($action == 'add') { $error=0; + $db->begin(); + // Create account - $account = new Account($db); + $object = new Account($db); - $account->ref = dol_sanitizeFileName(trim($_POST["ref"])); - $account->label = trim($_POST["label"]); - $account->courant = $_POST["type"]; - $account->clos = $_POST["clos"]; - $account->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1; - $account->url = $_POST["url"]; + $object->ref = dol_sanitizeFileName(trim($_POST["ref"])); + $object->label = trim($_POST["label"]); + $object->courant = $_POST["type"]; + $object->clos = $_POST["clos"]; + $object->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1; + $object->url = $_POST["url"]; - $account->bank = trim($_POST["bank"]); - $account->code_banque = trim($_POST["code_banque"]); - $account->code_guichet = trim($_POST["code_guichet"]); - $account->number = trim($_POST["number"]); - $account->cle_rib = trim($_POST["cle_rib"]); - $account->bic = trim($_POST["bic"]); - $account->iban = trim($_POST["iban"]); - $account->domiciliation = trim($_POST["domiciliation"]); + $object->bank = trim($_POST["bank"]); + $object->code_banque = trim($_POST["code_banque"]); + $object->code_guichet = trim($_POST["code_guichet"]); + $object->number = trim($_POST["number"]); + $object->cle_rib = trim($_POST["cle_rib"]); + $object->bic = trim($_POST["bic"]); + $object->iban = trim($_POST["iban"]); + $object->domiciliation = trim($_POST["domiciliation"]); - $account->proprio = trim($_POST["proprio"]); - $account->owner_address = trim($_POST["owner_address"]); + $object->proprio = trim($_POST["proprio"]); + $object->owner_address = trim($_POST["owner_address"]); $account_number = GETPOST('account_number','alpha'); - if ($account_number <= 0) { $account->account_number = ''; } else { $account->account_number = $account_number; } - $account->accountancy_journal = trim($_POST["accountancy_journal"]); + if ($account_number <= 0) { $object->account_number = ''; } else { $object->account_number = $account_number; } + $object->accountancy_journal = trim($_POST["accountancy_journal"]); - $account->solde = $_POST["solde"]; - $account->date_solde = dol_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); + $object->solde = $_POST["solde"]; + $object->date_solde = dol_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); - $account->currency_code = trim($_POST["account_currency_code"]); + $object->currency_code = trim($_POST["account_currency_code"]); - $account->state_id = $_POST["account_state_id"]; - $account->country_id = $_POST["account_country_id"]; + $object->state_id = $_POST["account_state_id"]; + $object->country_id = $_POST["account_country_id"]; - $account->min_allowed = GETPOST("account_min_allowed",'int'); - $account->min_desired = GETPOST("account_min_desired",'int'); - $account->comment = trim($_POST["account_comment"]); + $object->min_allowed = GETPOST("account_min_allowed",'int'); + $object->min_desired = GETPOST("account_min_desired",'int'); + $object->comment = trim($_POST["account_comment"]); - if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($account->account_number)) + $object->fk_user_author = $user->id; + + if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number)) { setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), null, 'error'); $action='create'; // Force chargement page en mode creation $error++; } - if (empty($account->ref)) + if (empty($object->ref)) { setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors'); $action='create'; // Force chargement page en mode creation $error++; } - if (empty($account->label)) + if (empty($object->label)) { setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("LabelBankCashAccount")), null, 'errors'); $action='create'; // Force chargement page en mode creation @@ -125,79 +134,91 @@ if ($_POST["action"] == 'add') } // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels,$account); + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); if (! $error) { - $id = $account->create($user); + $id = $object->create($user); if ($id > 0) { // Category association $categories = GETPOST('categories'); - $account->setCategories($categories); + $object->setCategories($categories); $_GET["id"]=$id; // Force chargement page en mode visu + + $action=''; } else { - setEventMessages($account->error, $account->errors, 'errors'); + $error++; + setEventMessages($object->error, $object->errors, 'errors'); $action='create'; // Force chargement page en mode creation } } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + } } -if ($_POST["action"] == 'update' && ! $_POST["cancel"]) +if ($action == 'update') { $error=0; // Update account - $account = new Account($db); - $account->fetch($_POST["id"]); + $object = new Account($db); + $object->fetch($_POST["id"]); - $account->ref = dol_string_nospecial(trim($_POST["ref"])); - $account->label = trim($_POST["label"]); - $account->courant = $_POST["type"]; - $account->clos = $_POST["clos"]; - $account->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1; - $account->url = trim($_POST["url"]); + $object->ref = dol_string_nospecial(trim($_POST["ref"])); + $object->label = trim($_POST["label"]); + $object->courant = $_POST["type"]; + $object->clos = $_POST["clos"]; + $object->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1; + $object->url = trim($_POST["url"]); - $account->bank = trim($_POST["bank"]); - $account->code_banque = trim($_POST["code_banque"]); - $account->code_guichet = trim($_POST["code_guichet"]); - $account->number = trim($_POST["number"]); - $account->cle_rib = trim($_POST["cle_rib"]); - $account->bic = trim($_POST["bic"]); - $account->iban = trim($_POST["iban"]); - $account->domiciliation = trim($_POST["domiciliation"]); + $object->bank = trim($_POST["bank"]); + $object->code_banque = trim($_POST["code_banque"]); + $object->code_guichet = trim($_POST["code_guichet"]); + $object->number = trim($_POST["number"]); + $object->cle_rib = trim($_POST["cle_rib"]); + $object->bic = trim($_POST["bic"]); + $object->iban = trim($_POST["iban"]); + $object->domiciliation = trim($_POST["domiciliation"]); - $account->proprio = trim($_POST["proprio"]); - $account->owner_address = trim($_POST["owner_address"]); + $object->proprio = trim($_POST["proprio"]); + $object->owner_address = trim($_POST["owner_address"]); $account_number = GETPOST('account_number', 'int'); - if ($account_number <= 0) { $account->account_number = ''; } else { $account->account_number = $account_number; } - $account->accountancy_journal = trim($_POST["accountancy_journal"]); + if ($account_number <= 0) { $object->account_number = ''; } else { $object->account_number = $account_number; } + $object->accountancy_journal = trim($_POST["accountancy_journal"]); - $account->currency_code = trim($_POST["account_currency_code"]); + $object->currency_code = trim($_POST["account_currency_code"]); - $account->state_id = $_POST["account_state_id"]; - $account->country_id = $_POST["account_country_id"]; + $object->state_id = $_POST["account_state_id"]; + $object->country_id = $_POST["account_country_id"]; - $account->min_allowed = GETPOST("account_min_allowed",'int'); - $account->min_desired = GETPOST("account_min_desired",'int'); - $account->comment = trim($_POST["account_comment"]); + $object->min_allowed = GETPOST("account_min_allowed",'int'); + $object->min_desired = GETPOST("account_min_desired",'int'); + $object->comment = trim($_POST["account_comment"]); - if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($account->account_number)) + if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number)) { setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), null, 'error'); $action='edit'; // Force chargement page en mode creation $error++; } - if (empty($account->ref)) + if (empty($object->ref)) { setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref")), null, 'errors'); $action='edit'; // Force chargement page en mode creation $error++; } - if (empty($account->label)) + if (empty($object->label)) { setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("LabelBankCashAccount")), null, 'errors'); $action='edit'; // Force chargement page en mode creation @@ -205,22 +226,22 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"]) } // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels,$account); + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); if (! $error) { - $result = $account->update($user); + $result = $object->update($user); if ($result >= 0) { // Category association $categories = GETPOST('categories'); - $account->setCategories($categories); + $object->setCategories($categories); $_GET["id"]=$_POST["id"]; // Force chargement page en mode visu } else { - setEventMessages($account->error, $account->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); $action='edit'; // Force chargement page edition } } @@ -229,9 +250,9 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"]) if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer) { // Delete - $account = new Account($db); - $account->fetch($_GET["id"]); - $account->delete(); + $object = new Account($db); + $object->fetch($_GET["id"]); + $object->delete(); header("Location: ".DOL_URL_ROOT."/compta/bank/index.php"); exit; @@ -258,7 +279,7 @@ llxHeader("",$title,$helpurl); if ($action == 'create') { - $account=new Account($db); + $object=new Account($db); print load_fiche_titre($langs->trans("NewFinancialAccount"), '', 'title_bank.png'); @@ -289,7 +310,7 @@ if ($action == 'create') // Ref print ''; - print ''; + print ''; // Label print ''; @@ -304,7 +325,7 @@ if ($action == 'create') // Currency print ''; print ''; print ''; // Country $selectedcode=''; if (isset($_POST["account_country_id"])) { - $selectedcode=$_POST["account_country_id"]?$_POST["account_country_id"]:$account->country_code; + $selectedcode=$_POST["account_country_id"]?$_POST["account_country_id"]:$object->country_code; } else if (empty($selectedcode)) $selectedcode=$mysoc->country_code; - $account->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules + $object->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules print ''; print ''; // Other attributes $parameters=array('colspan' => 3); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$account,$action); // Note that $action and $object may have been modified by hook + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { - print $account->showOptionals($extrafields,'edit',$parameters); + print $object->showOptionals($extrafields,'edit',$parameters); } print '
' . $langs->trans('Ref') . ''; - print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref'); - print '
'; - print ''; - if ($action != 'refcustomer' && $object->brouillon) - print ''; - print '
'; - print $langs->trans('RefCustomer') . ''; - print '' . img_edit($langs->trans('Modify')) . '
'; - print '
'; - if ($user->rights->commande->creer && $action == 'refcustomer') { - print '
'; - print ''; - print ''; - print ''; - print ' '; - print '
'; - } else { - print $object->ref_client; - } - print '
'; - print ''; - print ''; - print ''; - print '
' . $langs->trans('Company') . ''; - if (! empty($conf->global->COMMANDE_CHANGE_THIRDPARTY) && $action != 'editthirdparty' && $object->brouillon && $user->rights->commande->creer) - print 'id . '">' . img_edit($langs->trans('SetLinkToThirdParty'), 1) . '
'; - print '
'; - if ($action == 'editthirdparty') { - $form->form_thirdparty($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, 'socid','client>0'); - } else { - print $soc->getNomUrl(1, 'compta'); - } - print '
'; - print ''; - if ($action != 'classify') - print ''; - print '
'; - print $langs->trans('Project'); - print '' . img_edit($langs->trans('SetProject')) . '
'; - print '
'; - // print "$object->id, $object->socid, $object->fk_project"; - if ($action == 'classify') { - $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1); - } else { - $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0); - } - print '
'.$langs->trans("Ref").'ref).'" maxlength="12">
ref).'" maxlength="12">
'.$langs->trans("LabelBankCashAccount").'
'.$langs->trans("Currency").''; - $selectedcode=$account->currency_code; + $selectedcode=$object->currency_code; if (! $selectedcode) $selectedcode=$conf->currency; print $form->selectCurrency((isset($_POST["account_currency_code"])?$_POST["account_currency_code"]:$selectedcode), 'account_currency_code'); //print $langs->trans("Currency".$conf->currency); @@ -314,17 +335,17 @@ if ($action == 'create') // Status print '
'.$langs->trans("Status").''; - print $form->selectarray("clos", $account->status,(isset($_POST["clos"])?$_POST["clos"]:$account->clos)); + print $form->selectarray("clos", $object->status,(isset($_POST["clos"])?$_POST["clos"]:$object->clos)); print '
'.$langs->trans("BankAccountCountry").''; @@ -354,7 +375,7 @@ if ($action == 'create') print '
'.$langs->trans("Categories").''; $cate_arbo = $form->select_all_categories(Categorie::TYPE_ACCOUNT, '', 'parent', 64, 0, 1); $c = new Categorie($db); - $cats = $c->containing($account->id,Categorie::TYPE_ACCOUNT); + $cats = $c->containing($object->id,Categorie::TYPE_ACCOUNT); foreach($cats as $cat) { $arrayselected[] = $cat->id; } @@ -367,16 +388,16 @@ if ($action == 'create') print ''; // Editor wysiwyg require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor=new DolEditor('account_comment',(GETPOST("account_comment")?GETPOST("account_comment"):$account->comment),'',90,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,4,70); + $doleditor=new DolEditor('account_comment',(GETPOST("account_comment")?GETPOST("account_comment"):$object->comment),'',90,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,4,70); $doleditor->Create(); print '
'; @@ -387,7 +408,7 @@ if ($action == 'create') // Sold print ''.$langs->trans("InitialBankBalance").''; - print 'solde)).'">'; + print 'solde)).'">'; print ''.$langs->trans("Date").''; print ''; @@ -395,10 +416,10 @@ if ($action == 'create') print ''; print ''.$langs->trans("BalanceMinimalAllowed").''; - print 'min_allowed).'">'; + print 'min_allowed).'">'; print ''.$langs->trans("BalanceMinimalDesired").''; - print 'min_desired).'">'; + print 'min_desired).'">'; print ''; print '
'; @@ -409,56 +430,56 @@ if ($action == 'create') // If bank account print ''.$langs->trans("BankName").''; - print ''; + print ''; print ''; // Show fields of bank account - foreach ($account->getFieldsToShow() as $val) { + foreach ($object->getFieldsToShow() as $val) { if ($val == 'BankCode') { $name = 'code_banque'; $size = 8; - $content = $account->code_banque; + $content = $object->code_banque; } elseif ($val == 'DeskCode') { $name = 'code_guichet'; $size = 8; - $content = $account->code_guichet; + $content = $object->code_guichet; } elseif ($val == 'BankAccountNumber') { $name = 'number'; $size = 18; - $content = $account->number; + $content = $object->number; } elseif ($val == 'BankAccountNumberKey') { $name = 'cle_rib'; $size = 3; - $content = $account->cle_rib; + $content = $object->cle_rib; } print ''.$langs->trans($val).''; print ''; print ''; } - $ibankey = FormBank::getIBANLabel($account); + $ibankey = FormBank::getIBANLabel($object); $bickey="BICNumber"; - if ($account->getCountryCode() == 'IN') $bickey="SWIFT"; + if ($object->getCountryCode() == 'IN') $bickey="SWIFT"; // IBAN print ''.$langs->trans($ibankey).''; - print ''; + print ''; print ''.$langs->trans($bickey).''; - print ''; + print ''; print ''.$langs->trans("BankAccountDomiciliation").''; print ""; print ''.$langs->trans("BankAccountOwner").''; - print ''; + print ''; print ''; print ''.$langs->trans("BankAccountOwnerAddress").''; print ""; print ''; @@ -473,13 +494,13 @@ if ($action == 'create') { print ''.$langs->trans("AccountancyCode").''; print ''; - print $formaccountancy->select_account($account->account_number, 'account_number', 1, '', 1, 1); + print $formaccountancy->select_account($object->account_number, 'account_number', 1, '', 1, 1); print ''; } else { print ''.$langs->trans("AccountancyCode").''; - print 'account_number).'">'; + print 'account_number).'">'; } } else @@ -488,13 +509,13 @@ if ($action == 'create') { print ''.$langs->trans("AccountancyCode").''; print ''; - print $formaccountancy->select_account($account->account_number, 'account_number', 1, '', 1, 1); + print $formaccountancy->select_account($object->account_number, 'account_number', 1, '', 1, 1); print ''; } else { print ''.$langs->trans("AccountancyCode").''; - print 'account_number).'">'; + print 'account_number).'">'; } } @@ -502,7 +523,7 @@ if ($action == 'create') if (! empty($conf->accounting->enabled)) { print ''.$langs->trans("AccountancyJournal").''; - print 'accountancy_journal).'">'; + print 'accountancy_journal).'">'; } print ''; @@ -526,15 +547,15 @@ else { if (($_GET["id"] || $_GET["ref"]) && $action != 'edit') { - $account = new Account($db); + $object = new Account($db); if ($_GET["id"]) { - $account->fetch($_GET["id"]); + $object->fetch($_GET["id"]); } if ($_GET["ref"]) { - $account->fetch(0,$_GET["ref"]); - $_GET["id"]=$account->id; + $object->fetch(0,$_GET["ref"]); + $_GET["id"]=$object->id; } /* @@ -542,123 +563,162 @@ else */ // Onglets - $head=bank_prepare_head($account); + $head=bank_prepare_head($object); dol_fiche_head($head, 'bankname', $langs->trans("FinancialAccount"),0,'account'); - /* - * Confirmation to delete - */ + $formconfirm = ''; + + // Confirmation to delete if ($action == 'delete') { - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$account->id,$langs->trans("DeleteAccount"),$langs->trans("ConfirmDeleteAccount"),"confirm_delete"); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans("DeleteAccount"),$langs->trans("ConfirmDeleteAccount"),"confirm_delete"); } + // Print form confirm + print $formconfirm; + + $linkback = ''.$langs->trans("BackToList").''; + + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + + + print '
'; + print '
'; + print '
'; + print ''; - $linkback = ''.$langs->trans("BackToList").''; // Ref + /* print ''; print ''; + print $form->showrefnav($object, 'ref', $linkback, 1, 'ref'); + print '';*/ // Label - print ''; - print ''; + /*print ''; + print '';*/ // Type print ''; - print ''; + print ''; // Currency print ''; - print ''; // Status - print ''; - print ''; + /*print ''; + print '';*/ // Country + /* print ''; // State print ''; + if ($object->state_id > 0) print getState($object->state_id); + print '';*/ // Conciliate print ''; - print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; - print '\n"; // Categories - if($conf->categorie->enabled) { - print '"; } print ''; - print ''; + print ''; // Other attributes - $parameters=array('colspan' => 3); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$account,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook) && ! empty($extrafields->attribute_label)) - { - print $account->showOptionals($extrafields); - } - + $cols = 2; + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; + print '
'.$langs->trans("Ref").''; - print $form->showrefnav($account, 'ref', $linkback, 1, 'ref'); - print '
'.$langs->trans("Label").''.$account->label.'
'.$langs->trans("Label").''.$object->label.'
'.$langs->trans("AccountType").''.$account->type_lib[$account->type].'
'.$object->type_lib[$object->type].'
'.$langs->trans("Currency").''; - $selectedcode=$account->currency_code; + print ''; + $selectedcode=$object->currency_code; if (! $selectedcode) $selectedcode=$conf->currency; print $langs->trans("Currency".$selectedcode); print '
'.$langs->trans("Status").''.$account->getLibStatut(4).'
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("BankAccountCountry").''; - if ($account->country_id > 0) + if ($object->country_id > 0) { - $img=picto_from_langcode($account->country_code); + $img=picto_from_langcode($object->country_code); print $img?$img.' ':''; - print getCountry($account->getCountryCode(),0,$db); + print getCountry($object->getCountryCode(),0,$db); } print '
'.$langs->trans('State').''; - if ($account->state_id > 0) print getState($account->state_id); - print '
'.$langs->trans("Conciliable").''; - $conciliate=$account->canBeConciliated(); + print ''; + $conciliate=$object->canBeConciliated(); if ($conciliate == -2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')'; else if ($conciliate == -3) print $langs->trans("No").' ('.$langs->trans("Closed").')'; - else print ($account->rappro==1 ? $langs->trans("Yes") : ($langs->trans("No").' ('.$langs->trans("ConciliationDisabled").')')); + else print ($object->rappro==1 ? $langs->trans("Yes") : ($langs->trans("No").' ('.$langs->trans("ConciliationDisabled").')')); print '
'.$langs->trans("BalanceMinimalAllowed").''.$account->min_allowed.'
'.$object->min_allowed.'
'.$langs->trans("BalanceMinimalDesired").''.$account->min_desired.'
'.$object->min_desired.'
'.$langs->trans("Web").''; - if ($account->url) print ''; - print $account->url; - if ($account->url) print ''; + print '
'.$langs->trans("Web").''; + if ($object->url) print ''; + print $object->url; + if ($object->url) print ''; print "
'.$langs->trans("Categories").''; - print $form->showCategories($account->id,'account',1); + if ($conf->categorie->enabled) { + print '
'.$langs->trans("Categories").''; + print $form->showCategories($object->id,'account',1); print "
'.$langs->trans("Comment").''.dol_htmlentitiesbr($account->comment).'
'.dol_htmlentitiesbr($object->comment).'
'; - print '
'; + + print '
'; + print '
'; + print '
'; + print '
'; - if ($account->type == Account::TYPE_SAVINGS || $account->type == Account::TYPE_CURRENT) + + print ''; + + // Accountancy code + print ''; + print ''; + } else { + print $object->account_number; + } + print ''; + + // Accountancy journal + if (! empty($conf->accounting->enabled)) { - print '
'.$langs->trans("AccountancyCode").''; + if (! empty($conf->accounting->enabled)) { + print length_accountg($object->account_number).'
'; + print ''; + print ''; + } + + print '
'.$langs->trans("AccountancyJournal").''.$object->accountancy_journal.'
'; + + + if ($object->type == Account::TYPE_SAVINGS || $object->type == Account::TYPE_CURRENT) + { + print '
'; + + print ''; - print ''; - print ''; + print ''; + print ''; // Show fields of bank account - foreach ($account->getFieldsToShow() as $val) { + foreach ($object->getFieldsToShow() as $val) { if ($val == 'BankCode') { - $content = $account->code_banque; + $content = $object->code_banque; } elseif ($val == 'DeskCode') { - $content = $account->code_guichet; + $content = $object->code_guichet; } elseif ($val == 'BankAccountNumber') { - $content = $account->number; + $content = $object->number; } elseif ($val == 'BankAccountNumberKey') { - $content = $account->cle_rib; + $content = $object->cle_rib; } print ''; @@ -666,14 +726,14 @@ else print ''; } - $ibankey = FormBank::getIBANLabel($account); + $ibankey = FormBank::getIBANLabel($object); $bickey="BICNumber"; - if ($account->getCountryCode() == 'IN') $bickey="SWIFT"; + if ($object->getCountryCode() == 'IN') $bickey="SWIFT"; print ''; - print ''; print ''; - print ''; - print '\n"; - print '\n"; - print '\n"; print '
'.$langs->trans("BankName").''.$account->bank.'
'.$langs->trans("BankName").''.$object->bank.'
'.$langs->trans($val).'
'.$langs->trans($ibankey).''.$account->iban.' '; - if (! empty($account->iban)) { - if (! checkIbanForAccount($account)) { + print ''.$object->iban.' '; + if (! empty($object->iban)) { + if (! checkIbanForAccount($object)) { print img_picto($langs->trans("IbanNotValid"),'warning'); } else { print img_picto($langs->trans("IbanValid"),'info'); @@ -682,9 +742,9 @@ else print '
'.$langs->trans($bickey).''.$account->bic.' '; - if (! empty($account->bic)) { - if (! checkSwiftForAccount($account)) { + print ''.$object->bic.' '; + if (! empty($object->bic)) { + if (! checkSwiftForAccount($object)) { print img_picto($langs->trans("SwiftNotValid"),'warning'); } else { print img_picto($langs->trans("SwiftValid"),'info'); @@ -692,44 +752,28 @@ else } print '
'.$langs->trans("BankAccountDomiciliation").''; - print nl2br($account->domiciliation); + print '
'.$langs->trans("BankAccountDomiciliation").''; + print nl2br($object->domiciliation); print "
'.$langs->trans("BankAccountOwner").''; - print $account->proprio; + print '
'.$langs->trans("BankAccountOwner").''; + print $object->proprio; print "
'.$langs->trans("BankAccountOwnerAddress").''; - print nl2br($account->owner_address); + print '
'.$langs->trans("BankAccountOwnerAddress").''; + print nl2br($object->owner_address); print "
'; - print '
'; } - print ''; - // Accountancy code - print ''; - print ''; - } else { - print $account->account_number; - } - print ''; - - // Accountancy journal - if (! empty($conf->accounting->enabled)) - { - print ''; - print ''; - } - - print '
'.$langs->trans("AccountancyCode").''; - if (! empty($conf->accounting->enabled)) { - print length_accountg($account->account_number).'
'.$langs->trans("AccountancyJournal").''.$account->accountancy_journal.'
'; - + print '
'; + print '
'; print '
'; + print '
'; + + dol_fiche_end(); /* * Barre d'actions @@ -738,13 +782,13 @@ else if ($user->rights->banque->configurer) { - print 'id.'">'.$langs->trans("Modify").''; + print 'id.'">'.$langs->trans("Modify").''; } - $canbedeleted=$account->can_be_deleted(); // Renvoi vrai si compte sans mouvements + $canbedeleted=$object->can_be_deleted(); // Renvoi vrai si compte sans mouvements if ($user->rights->banque->configurer && $canbedeleted) { - print 'id.'">'.$langs->trans("Delete").''; + print 'id.'">'.$langs->trans("Delete").''; } print ''; @@ -759,8 +803,8 @@ else if (GETPOST('id','int') && $action == 'edit' && $user->rights->banque->configurer) { - $account = new Account($db); - $account->fetch(GETPOST('id','int')); + $object = new Account($db); + $object->fetch(GETPOST('id','int')); print load_fiche_titre($langs->trans("EditFinancialAccount"), '', 'title_bank.png'); @@ -783,7 +827,7 @@ else print ''."\n"; } - print '
'; + print ''; print ''; print ''; print ''."\n\n"; @@ -794,24 +838,24 @@ else // Ref print ''.$langs->trans("Ref").''; - print 'ref).'">'; + print 'ref).'">'; // Label print ''.$langs->trans("Label").''; - print 'label).'">'; + print 'label).'">'; // Type print ''.$langs->trans("AccountType").''; print ''; - $formbank->selectTypeOfBankAccount((isset($_POST["type"])?$_POST["type"]:$account->type),"type"); + $formbank->selectTypeOfBankAccount((isset($_POST["type"])?$_POST["type"]:$object->type),"type"); print ''; // Currency print ''.$langs->trans("Currency"); - print ''; + print ''; print ''; print ''; - $selectedcode=$account->currency_code; + $selectedcode=$object->currency_code; if (! $selectedcode) $selectedcode=$conf->currency; print $form->selectCurrency((isset($_POST["account_currency_code"])?$_POST["account_currency_code"]:$selectedcode), 'account_currency_code'); //print $langs->trans("Currency".$conf->currency); @@ -821,15 +865,15 @@ else // Status print ''.$langs->trans("Status").''; print ''; - print $form->selectarray("clos", $account->status,(isset($_POST["clos"])?$_POST["clos"]:$account->clos)); + print $form->selectarray("clos", $object->status,(isset($_POST["clos"])?$_POST["clos"]:$object->clos)); print ''; // Country - $account->country_id=$account->country_id?$account->country_id:$mysoc->country_id; - $selectedcode=$account->country_code; + $object->country_id=$object->country_id?$object->country_id:$mysoc->country_id; + $selectedcode=$object->country_code; if (isset($_POST["account_country_id"])) $selectedcode=$_POST["account_country_id"]; else if (empty($selectedcode)) $selectedcode=$mysoc->country_code; - $account->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules + $object->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules print ''.$langs->trans("Country").''; print ''; @@ -841,7 +885,7 @@ else print ''.$langs->trans('State').''; if ($selectedcode) { - print $formcompany->select_state(isset($_POST["account_state_id"])?$_POST["account_state_id"]:$account->state_id,$selectedcode,'account_state_id'); + print $formcompany->select_state(isset($_POST["account_state_id"])?$_POST["account_state_id"]:$object->state_id,$selectedcode,'account_state_id'); } else { @@ -852,7 +896,7 @@ else // Conciliable print ''.$langs->trans("Conciliable").''; print ''; - $conciliate=$account->canBeConciliated(); + $conciliate=$object->canBeConciliated(); if ($conciliate == -2) print $langs->trans("No").' ('.$langs->trans("CashAccount").')'; else if ($conciliate == -3) print $langs->trans("No").' ('.$langs->trans("Closed").')'; else print ' 0)?'':' checked="checked"').'"> '.$langs->trans("DisableConciliation"); @@ -860,14 +904,14 @@ else // Balance print ''.$langs->trans("BalanceMinimalAllowed").''; - print 'min_allowed).'">'; + print 'min_allowed).'">'; print ''.$langs->trans("BalanceMinimalDesired").''; - print 'min_desired).'">'; + print 'min_desired).'">'; // Web print ''.$langs->trans("Web").''; - print 'url).'">'; + print 'url).'">'; print ''; // Tags-Categories @@ -889,16 +933,16 @@ else print ''; // Editor wysiwyg require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor=new DolEditor('account_comment',(GETPOST("account_comment")?GETPOST("account_comment"):$account->comment),'',90,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,4,70); + $doleditor=new DolEditor('account_comment',(GETPOST("account_comment")?GETPOST("account_comment"):$object->comment),'',90,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,4,70); $doleditor->Create(); print ''; // Other attributes $parameters=array('colspan' => 3); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$account,$action); // Note that $action and $object may have been modified by hook + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { - print $account->showOptionals($extrafields,'edit'); + print $object->showOptionals($extrafields,'edit'); } print ''; print '
'; @@ -909,27 +953,27 @@ else // If bank account print ''.$langs->trans("BankName").''; - print ''; + print ''; print ''; // Show fields of bank account - foreach ($account->getFieldsToShow() as $val) { + foreach ($object->getFieldsToShow() as $val) { if ($val == 'BankCode') { $name = 'code_banque'; $size = 8; - $content = $account->code_banque; + $content = $object->code_banque; } elseif ($val == 'DeskCode') { $name = 'code_guichet'; $size = 8; - $content = $account->code_guichet; + $content = $object->code_guichet; } elseif ($val == 'BankAccountNumber') { $name = 'number'; $size = 18; - $content = $account->number; + $content = $object->number; } elseif ($val == 'BankAccountNumberKey') { $name = 'cle_rib'; $size = 3; - $content = $account->cle_rib; + $content = $object->cle_rib; } print ''.$langs->trans($val).''; @@ -937,29 +981,29 @@ else print ''; } - $ibankey = FormBank::getIBANLabel($account); + $ibankey = FormBank::getIBANLabel($object); $bickey="BICNumber"; - if ($account->getCountryCode() == 'IN') $bickey="SWIFT"; + if ($object->getCountryCode() == 'IN') $bickey="SWIFT"; // IBAN print ''.$langs->trans($ibankey).''; - print ''; + print ''; print ''.$langs->trans($bickey).''; - print ''; + print ''; print ''.$langs->trans("BankAccountDomiciliation").''; print ""; print ''.$langs->trans("BankAccountOwner").''; - print ''; + print ''; print ''; print ''.$langs->trans("BankAccountOwnerAddress").''; print ""; print ''; @@ -978,9 +1022,9 @@ else print ''.$langs->trans("AccountancyCode").''; print ''; if (!empty($conf->accounting->enabled)) { - print $formaccountancy->select_account($account->account_number, 'account_number', 1, '', 1, 1); + print $formaccountancy->select_account($object->account_number, 'account_number', 1, '', 1, 1); } else { - print 'account_number).'">'; + print 'account_number).'">'; } print ''; @@ -988,7 +1032,7 @@ else if (! empty($conf->accounting->enabled)) { print ''.$langs->trans("AccountancyJournal").''; - print 'accountancy_journal).'">'; + print 'accountancy_journal).'">'; } print ''; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 922f2636767..dfeea54c510 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -38,7 +38,8 @@ class Account extends CommonObject { public $element = 'bank_account'; public $table_element = 'bank_account'; - + public $picto = 'account'; + /** * @var int Use id instead of rowid * @deprecated @@ -500,9 +501,10 @@ class Account extends CommonObject * Create bank account into database * * @param User $user Object user making creation + * @param int $notrigger 1=Disable triggers * @return int < 0 if KO, > 0 if OK */ - function create(User $user = null) + function create(User $user = null, $notrigger=0) { global $langs,$conf, $hookmanager; @@ -537,6 +539,8 @@ class Account extends CommonObject $now=dol_now(); + $this->db->begin(); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account ("; $sql.= "datec"; $sql.= ", ref"; @@ -593,7 +597,7 @@ class Account extends CommonObject { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_account"); - $result=$this->update($user); + $result=$this->update($user, 1); if ($result > 0) { $accline = new AccountLine($this->db); @@ -606,52 +610,68 @@ class Account extends CommonObject $accline->fk_type = 'SOLD'; if ($accline->insert() < 0) { - return -3; + $error++; } - // Actions on extra fields (by external module or standard code) - $hookmanager->initHooks(array('bankdao')); - $parameters=array('id'=>$this->id); - $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - if (empty($reshook)) + if (! $error) + { + $result=$this->insertExtraFields(); + if ($result < 0) $error++; + } + + if (! $error && ! $notrigger) { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $result=$this->insertExtraFields(); - if ($result < 0) - { - return -4; - } - } - } - else if ($reshook < 0) return -5; + // Call trigger + $result=$this->call_trigger('BANKACCOUNT_CREATE',$user); + if ($result < 0) $error++; + // End call triggers + } + } + else + { + $error++; } - return $this->id; } else { if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error=$langs->trans("ErrorBankLabelAlreadyExists"); - return -1; + $error++; } else { $this->error=$this->db->error()." sql=".$sql; - return -2; + $error++; } } + + if (! $error) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -1*$error; + } } /** * Update bank account card * * @param User $user Object user making action + * @param int $notrigger 1=Disable triggers * @return int <0 si ko, >0 si ok */ - function update(User $user = null) + function update(User $user = null, $notrigger = 0) { global $langs,$conf, $hookmanager; + $error=0; + + $this->db->begin(); + // Clean parameters $this->state_id = ($this->state_id?$this->state_id:$this->state_id); $this->country_id = ($this->country_id?$this->country_id:$this->country_id); @@ -710,33 +730,41 @@ class Account extends CommonObject $result = $this->db->query($sql); if ($result) { - // Actions on extra fields (by external module or standard code) - $hookmanager->initHooks(array('bankdao')); - $parameters=array('id'=>$this->id); - $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - if (empty($reshook)) - { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $result=$this->insertExtraFields(); - if ($result < 0) - { - return -1; - } - } - } - else if ($reshook < 0) return -1; - - - return 1; + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + if (! $error) + { + $result=$this->insertExtraFields(); + if ($result < 0) $error++; + } + } + + if (! $error && ! $notrigger) + { + // Call trigger + $result=$this->call_trigger('BANKACCOUNT_UPDATE',$user); + if ($result < 0) $error++; + // End call triggers + } } else { + $error++; $this->error=$this->db->lasterror(); dol_print_error($this->db); - return -1; } + + if (! $error) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -1*$error; + } } @@ -980,10 +1008,10 @@ class Account extends CommonObject /** - * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) + * Return label of object status * - * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long - * @return string Libelle + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto + * @return string Label */ function getLibStatut($mode=0) { @@ -991,11 +1019,11 @@ class Account extends CommonObject } /** - * Renvoi le libelle d'un statut donne + * Return label of given object status * - * @param int $statut Id statut - * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto - * @return string Libelle du statut + * @param int $statut Id statut + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto + * @return string Label */ function LibStatut($statut, $mode = 0) { @@ -1018,6 +1046,8 @@ class Account extends CommonObject return $picto.' '.$label; } elseif ($mode == 5) { return $label.' '.$picto; + } elseif ($mode == 6) { + return $label.' '.$picto; } //There is no short mode for this label @@ -1368,11 +1398,12 @@ class Account extends CommonObject * - DeskCode * * Some countries show less or more bank account properties to the user - * + * + * @param int $includeibanbic 1=Return also key for IBAN and BIC * @return array * @see useDetailedBBAN */ - public function getFieldsToShow() + public function getFieldsToShow($includeibanbic=0) { //Get the required properties depending on the country $detailedBBAN = $this->useDetailedBBAN(); @@ -1391,8 +1422,11 @@ class Account extends CommonObject } //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour) + if ($includeibanbic) + { $fieldarray[]='IBAN'; $fieldarray[]='BIC'; + } //} //Get the order the properties are shown @@ -1621,7 +1655,7 @@ class AccountLine extends CommonObject $sql .= ", '".$this->db->idate($this->datev)."'"; $sql .= ", '".$this->db->escape($this->label)."'"; $sql .= ", ".price2num($this->amount); - $sql .= ", '".$this->fk_user_author."'"; + $sql .= ", ".($this->fk_user_author > 0 ? "'".$this->fk_user_author."'":"null"); $sql .= ", ".($this->num_chq ? "'".$this->num_chq."'" : "null"); $sql .= ", '".$this->fk_account."'"; $sql .= ", '".$this->db->escape($this->fk_type)."'"; diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index c08d645cf53..99c425778e6 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -217,7 +217,7 @@ abstract class CommonInvoice extends CommonObject /** * Return label of object status * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto, 6=Long label + picto * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) * @return string Label */