From b064d1106b2f64a58048460b47a73bbc84c47024 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Thu, 17 Dec 2015 06:16:29 +0100 Subject: [PATCH 1/3] Accountancy Add a list to select accounting account on product card --- .../class/html.formventilation.class.php | 2 +- htdocs/product/card.php | 83 +++++++++++++------ 2 files changed, 57 insertions(+), 28 deletions(-) diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php index f92f5b3ab88..c4be176bf68 100644 --- a/htdocs/accountancy/class/html.formventilation.class.php +++ b/htdocs/accountancy/class/html.formventilation.class.php @@ -94,7 +94,7 @@ class FormVentilation extends Form * @param array $event Event options * @param int $select_in $selectid value is a aa.rowid (0 default) or aa.account_number (1) * @param int $select_out set value returned by select 0=rowid (default), 1=account_number - * @param int $aabase set accounting_account base class to display empty=all or from 1 to 8 will display only account beginning by + * @param int $aabase set accounting_account base class to display empty=all or from 1 to 8 will display only account beginning by this number * * @return string String with HTML select */ diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 77b14b24c7a..5f60724a135 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -43,9 +43,11 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; -if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; -if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; -if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; +if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; +if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; +if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; +if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php'; $langs->load("products"); $langs->load("other"); @@ -250,8 +252,11 @@ if (empty($reshook)) $object->volume_units = GETPOST('volume_units'); $object->finished = GETPOST('finished'); $object->fk_unit = GETPOST('units'); - $object->accountancy_code_sell = GETPOST('accountancy_code_sell'); - $object->accountancy_code_buy = GETPOST('accountancy_code_buy'); + + if (GETPOST('accountancy_code_sell') <= 0) { $accountancy_code_sell = ''; } else { $accountancy_code_sell = GETPOST('accountancy_code_sell'); } + if (GETPOST('accountancy_code_buy') <= 0) { $accountancy_code_buy = ''; } else { $accountancy_code_buy = GETPOST('accountancy_code_buy'); } + $object->accountancy_code_sell = $accountancy_code_sell; + $object->accountancy_code_buy = GETPOST('accountancy_code_buy'); // MultiPrix if (! empty($conf->global->PRODUIT_MULTIPRICES)) @@ -719,6 +724,7 @@ llxHeader('', $title, $helpurl); $form = new Form($db); $formproduct = new FormProduct($db); +if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db); if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) @@ -1003,20 +1009,34 @@ else } print ''; + + if (! empty($conf->accounting->enabled)) + { + // Accountancy_code_sell + print ''; + print ''; - // Accountancy_code_sell - print ''; - print ''; + // Accountancy_code_buy + print ''; + print ''; + } + else // For external software + { + // Accountancy_code_sell + print ''; + print ''; - // Accountancy_code_buy - print ''; - print ''; - - print '
'.$langs->trans("ProductAccountancySellCode").''; + print $formaccountancy->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 0, 1); + print '
'.$langs->trans("ProductAccountancySellCode").''; - print '
'.$langs->trans("ProductAccountancyBuyCode").''; + print $formaccountancy->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 0, 1); + print '
'.$langs->trans("ProductAccountancySellCode").''; + print '
'.$langs->trans("ProductAccountancyBuyCode").''; - print '
'; - - print '
'; + // Accountancy_code_buy + print ''.$langs->trans("ProductAccountancyBuyCode").''; + print ''; + print ''; + } + print ''; dol_fiche_end(); @@ -1263,14 +1283,24 @@ else print '
'; - /*if (empty($conf->accounting->enabled) && empty($conf->comptabilite->enabled) && empty($conf->accountingexpert->enabled)) - { - // Don't show accounting field when accounting id disabled. - } - else - {*/ - print ''; + print '
'; + if (! empty($conf->accounting->enabled)) + { + // Accountancy_code_sell + print ''; + print ''; + + // Accountancy_code_buy + print ''; + print ''; + } + else // For external software + { // Accountancy_code_sell print ''; print ''; print ''; - - print '
'.$langs->trans("ProductAccountancySellCode").''; + print $formaccountancy->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1); + print '
'.$langs->trans("ProductAccountancyBuyCode").''; + print $formaccountancy->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1); + print '
'.$langs->trans("ProductAccountancySellCode").''; @@ -1280,9 +1310,8 @@ else print '
'.$langs->trans("ProductAccountancyBuyCode").''; print '
'; - //} + } + print ''; dol_fiche_end(); From 85f87d45df929125e993da36d9cf2e7e242af316 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Thu, 17 Dec 2015 12:57:08 +0100 Subject: [PATCH 2/3] Add select account in product card --- .../class/html.formventilation.class.php | 4 +-- htdocs/product/card.php | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php index c4be176bf68..5ff125b0ba2 100644 --- a/htdocs/accountancy/class/html.formventilation.class.php +++ b/htdocs/accountancy/class/html.formventilation.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2013-2014 Olivier Geffroy - * Copyright (C) 2013-2014 Alexandre Spangaro + * Copyright (C) 2013-2015 Alexandre Spangaro * Copyright (C) 2015 Ari Elbaz (elarifr) * * This program is free software; you can redistribute it and/or modify @@ -126,7 +126,7 @@ class FormVentilation extends Form if ($num) { while ( $i < $num ) { $obj = $this->db->fetch_object($resql); - $label = $obj->account_number . ' - ' . $obj->label; + $label = length_accountg($obj->account_number) . ' - ' . $obj->label; $label = dol_trunc($label, $trunclength); if ($select_in == 0 ) $select_value_in = $obj->rowid; if ($select_in == 1 ) $select_value_in = $obj->account_number; diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 80deacdea88..3fce17da770 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -186,12 +186,14 @@ if (empty($reshook)) $action = "create"; $error++; } + /* if (! empty(GETPOST('duration_value')) && empty(GETPOST('duration_unit'))) { setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentities('Unit')), 'errors'); $action = "create"; $error++; } + */ if (! $error) { @@ -263,7 +265,7 @@ if (empty($reshook)) if (GETPOST('accountancy_code_sell') <= 0) { $accountancy_code_sell = ''; } else { $accountancy_code_sell = GETPOST('accountancy_code_sell'); } if (GETPOST('accountancy_code_buy') <= 0) { $accountancy_code_buy = ''; } else { $accountancy_code_buy = GETPOST('accountancy_code_buy'); } $object->accountancy_code_sell = $accountancy_code_sell; - $object->accountancy_code_buy = GETPOST('accountancy_code_buy'); + $object->accountancy_code_buy = $accountancy_code_buy; // MultiPrix if (! empty($conf->global->PRODUIT_MULTIPRICES)) @@ -372,6 +374,8 @@ if (empty($reshook)) $object->barcode_type_coder = $stdobject->barcode_type_coder; $object->barcode_type_label = $stdobject->barcode_type_label; + if (GETPOST('accountancy_code_sell') <= 0) { $accountancy_code_sell = ''; } else { $accountancy_code_sell = GETPOST('accountancy_code_sell'); } + if (GETPOST('accountancy_code_buy') <= 0) { $accountancy_code_buy = ''; } else { $accountancy_code_buy = GETPOST('accountancy_code_buy'); } $object->accountancy_code_sell = GETPOST('accountancy_code_sell'); $object->accountancy_code_buy = GETPOST('accountancy_code_buy'); @@ -1367,7 +1371,7 @@ else print ''; print ''; if (($action != 'editbarcodetype') && ! empty($user->rights->barcode->creer)) print ''; print '
'; print $langs->trans("BarcodeType"); - print ''; + print 'id.'">'.img_edit($langs->trans('Edit'),1).'
'; print ''; @@ -1388,7 +1392,7 @@ else print ''; print ''; if (($action != 'editbarcode') && ! empty($user->rights->barcode->creer)) print ''; print '
'; print $langs->trans("BarcodeValue"); - print ''; + print 'id.'">'.img_edit($langs->trans('Edit'),1).'
'; print ''; @@ -1409,13 +1413,23 @@ else } // Accountancy sell code - print ''.$form->editfieldkey("ProductAccountancySellCode",'accountancy_code_sell',$object->accountancy_code_sell,$object,$user->rights->produit->creer||$user->rights->service->creer,'string').''; - print $form->editfieldval("ProductAccountancySellCode",'accountancy_code_sell',$object->accountancy_code_sell,$object,$user->rights->produit->creer||$user->rights->service->creer,'string'); + print ''; + print ''; + print '
'; + print $langs->trans("ProductAccountancySellCode"); + print '
'; + print ''; + print length_accountg($object->accountancy_code_sell); print ''; - // Accountancy buy code - print ''.$form->editfieldkey("ProductAccountancyBuyCode",'accountancy_code_buy',$object->accountancy_code_buy,$object,$user->rights->produit->creer||$user->rights->service->creer,'string').''; - print $form->editfieldval("ProductAccountancyBuyCode",'accountancy_code_buy',$object->accountancy_code_buy,$object,$user->rights->produit->creer||$user->rights->service->creer,'string'); + // Accountancy sell code + print ''; + print ''; + print '
'; + print $langs->trans("ProductAccountancyBuyCode"); + print '
'; + print ''; + print length_accountg($object->accountancy_code_buy); print ''; // Status (to sell) From 07b42f2bd5dc24f4bd7f34943ecabb490c55de66 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Tue, 22 Dec 2015 07:31:59 +0100 Subject: [PATCH 3/3] Fix bug with empty code - return -1 --- htdocs/product/card.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 7b2d71a4c27..29ab2c0018c 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -157,6 +157,7 @@ if (empty($reshook)) } } + /* if ($action == 'setaccountancy_code_buy') { $result = $object->setAccountancyCode('buy', GETPOST('accountancy_code_buy')); @@ -170,6 +171,7 @@ if (empty($reshook)) if ($result < 0) setEventMessages(join(',',$object->errors), null, 'errors'); $action=""; } + */ // Add a product or service if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer)) @@ -262,10 +264,11 @@ if (empty($reshook)) $object->finished = GETPOST('finished'); $object->fk_unit = GETPOST('units'); - if (GETPOST('accountancy_code_sell') <= 0) { $accountancy_code_sell = ''; } else { $accountancy_code_sell = GETPOST('accountancy_code_sell'); } - if (GETPOST('accountancy_code_buy') <= 0) { $accountancy_code_buy = ''; } else { $accountancy_code_buy = GETPOST('accountancy_code_buy'); } - $object->accountancy_code_sell = $accountancy_code_sell; - $object->accountancy_code_buy = $accountancy_code_buy; + $accountancy_code_sell = GETPOST('accountancy_code_sell'); + $accountancy_code_buy = GETPOST('accountancy_code_buy'); + + if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; } + if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; } // MultiPrix if (! empty($conf->global->PRODUIT_MULTIPRICES)) @@ -374,10 +377,11 @@ if (empty($reshook)) $object->barcode_type_coder = $stdobject->barcode_type_coder; $object->barcode_type_label = $stdobject->barcode_type_label; - if (GETPOST('accountancy_code_sell') <= 0) { $accountancy_code_sell = ''; } else { $accountancy_code_sell = GETPOST('accountancy_code_sell'); } - if (GETPOST('accountancy_code_buy') <= 0) { $accountancy_code_buy = ''; } else { $accountancy_code_buy = GETPOST('accountancy_code_buy'); } - $object->accountancy_code_sell = GETPOST('accountancy_code_sell'); - $object->accountancy_code_buy = GETPOST('accountancy_code_buy'); + $accountancy_code_sell = GETPOST('accountancy_code_sell'); + $accountancy_code_buy = GETPOST('accountancy_code_buy'); + + if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; } + if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; } // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object);