diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 4d4cc401022..3648dc14a66 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -8,7 +8,7 @@ * Copyright (C) 2010-2015 Juanjo Menent * Copyright (C) 2013-2016 Marcos García * Copyright (C) 2012-2013 Cédric Salvador - * Copyright (C) 2011-2017 Alexandre Spangaro + * Copyright (C) 2011-2017 Alexandre Spangaro * Copyright (C) 2014 Cédric Gross * Copyright (C) 2014-2015 Ferran Marcet * Copyright (C) 2015 Jean-François Ferry @@ -306,9 +306,13 @@ if (empty($reshook)) $object->fk_unit = GETPOST('units'); $accountancy_code_sell = GETPOST('accountancy_code_sell'); + $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra'); + $accountancy_code_sell_export = GETPOST('accountancy_code_sell_export'); $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_sell_intra <= 0) { $object->accountancy_code_sell_intra = ''; } else { $object->accountancy_code_sell_intra = $accountancy_code_sell_intra; } + if ($accountancy_code_sell_export <= 0) { $object->accountancy_code_sell_export = ''; } else { $object->accountancy_code_sell_export = $accountancy_code_sell_export; } if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; } // MultiPrix @@ -430,9 +434,13 @@ if (empty($reshook)) $object->barcode_type_label = $stdobject->barcode_type_label; $accountancy_code_sell = GETPOST('accountancy_code_sell'); + $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra'); + $accountancy_code_sell_export = GETPOST('accountancy_code_sell_export'); $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_sell_intra <= 0) { $object->accountancy_code_sell_intra = ''; } else { $object->accountancy_code_sell_intra = $accountancy_code_sell_intra; } + if ($accountancy_code_sell_export <= 0) { $object->accountancy_code_sell_export = ''; } else { $object->accountancy_code_sell_export = $accountancy_code_sell_export; } 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 @@ -1154,42 +1162,64 @@ else if (! empty($conf->accounting->enabled)) { - // Accountancy_code_sell - print ''.$langs->trans("ProductAccountancySellCode").''; - print ''; - print $formaccounting->select_account(GETPOST('accountancy_code_sell'), 'accountancy_code_sell', 1, null, 1, 1, ''); - print ''; + // Accountancy_code_sell + print ''.$langs->trans("ProductAccountancySellCode").''; + print ''; + print $formaccounting->select_account(GETPOST('accountancy_code_sell'), 'accountancy_code_sell', 1, null, 1, 1, ''); + print ''; - // Accountancy_code_buy - print ''.$langs->trans("ProductAccountancyBuyCode").''; - print ''; + // Accountancy_code_sell_intra + print ''.$langs->trans("ProductAccountancySellIntraCode").''; + print ''; + print $formaccounting->select_account(GETPOST('accountancy_code_sell_intra'), 'accountancy_code_sell_intra', 1, null, 1, 1, ''); + print ''; + + // Accountancy_code_sell_export + print ''.$langs->trans("ProductAccountancySellExportCode").''; + print ''; + print $formaccounting->select_account(GETPOST('accountancy_code_sell_export'), 'accountancy_code_sell_export', 1, null, 1, 1, ''); + print ''; + + // Accountancy_code_buy + print ''.$langs->trans("ProductAccountancyBuyCode").''; + print ''; print $formaccounting->select_account(GETPOST('accountancy_code_buy'), 'accountancy_code_buy', 1, null, 1, 1, ''); - print ''; + print ''; } else // For external software { - // Accountancy_code_sell - print ''.$langs->trans("ProductAccountancySellCode").''; - print ''; - print ''; + // Accountancy_code_sell + print ''.$langs->trans("ProductAccountancySellCode").''; + print ''; + print ''; - // Accountancy_code_buy - print ''.$langs->trans("ProductAccountancyBuyCode").''; - print ''; - print ''; - } + // Accountancy_code_sell_intra + print ''.$langs->trans("ProductAccountancySellIntraCode").''; + print ''; + print ''; + + // Accountancy_code_sell_export + print ''.$langs->trans("ProductAccountancySellExportCode").''; + print ''; + print ''; + + // Accountancy_code_buy + print ''.$langs->trans("ProductAccountancyBuyCode").''; + print ''; + print ''; + } print ''; - dol_fiche_end(); + dol_fiche_end(); print '
'; print ''; - print '     '; + print '     '; print ''; print '
'; - print ''; - } + print ''; + } /* * Product card @@ -1448,42 +1478,64 @@ else if (! empty($conf->accounting->enabled)) { - // Accountancy_code_sell - print ''.$langs->trans("ProductAccountancySellCode").''; - print ''; + // Accountancy_code_sell + print ''.$langs->trans("ProductAccountancySellCode").''; + print ''; print $formaccounting->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1); - print ''; + print ''; - // Accountancy_code_buy - print ''.$langs->trans("ProductAccountancyBuyCode").''; - print ''; + // Accountancy_code_sell_intra + print ''.$langs->trans("ProductAccountancySellIntraCode").''; + print ''; + print $formaccounting->select_account($object->accountancy_code_sell_intra, 'accountancy_code_sell_intra', 1, '', 1, 1); + print ''; + + // Accountancy_code_sell_export + print ''.$langs->trans("ProductAccountancySellExportCode").''; + print ''; + print $formaccounting->select_account($object->accountancy_code_sell_export, 'accountancy_code_sell_export', 1, '', 1, 1); + print ''; + + // Accountancy_code_buy + print ''.$langs->trans("ProductAccountancyBuyCode").''; + print ''; print $formaccounting->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1); - print ''; + print ''; } else // For external software { - // Accountancy_code_sell - print ''.$langs->trans("ProductAccountancySellCode").''; - print ''; - print ''; + // Accountancy_code_sell + print ''.$langs->trans("ProductAccountancySellCode").''; + print ''; + print ''; - // Accountancy_code_buy - print ''.$langs->trans("ProductAccountancyBuyCode").''; - print ''; - print ''; - } + // Accountancy_code_sell_intra + print ''.$langs->trans("ProductAccountancySellIntraCode").''; + print ''; + print ''; + + // Accountancy_code_sell_export + print ''.$langs->trans("ProductAccountancySellExportCode").''; + print ''; + print ''; + + // Accountancy_code_buy + print ''.$langs->trans("ProductAccountancyBuyCode").''; + print ''; + print ''; + } print ''; - dol_fiche_end(); + dol_fiche_end(); - print '
'; + print '
'; print ''; print '     '; - print ''; + print ''; print '
'; - print ''; - } + print ''; + } // Fiche en mode visu else { @@ -1575,35 +1627,65 @@ else print ''."\n"; } - // Accountancy sell code + // Accountancy sell code print ''; - print $langs->trans("ProductAccountancySellCode"); - print ''; + print $langs->trans("ProductAccountancySellCode"); + print ''; if (! empty($conf->accounting->enabled)) { $accountingaccount = new AccountingAccount($db); $accountingaccount->fetch('',$object->accountancy_code_sell,1); print $accountingaccount->getNomUrl(0,1,1,'',1); - } else { + } else { print $object->accountancy_code_sell; } print ''; - // Accountancy buy code + // Accountancy sell code intra-community print ''; - print $langs->trans("ProductAccountancyBuyCode"); - print ''; + print $langs->trans("ProductAccountancySellIntraCode"); + print ''; if (! empty($conf->accounting->enabled)) { $accountingaccount2 = new AccountingAccount($db); - $accountingaccount2->fetch('',$object->accountancy_code_buy,1); + $accountingaccount2->fetch('',$object->accountancy_code_sell_intra,1); print $accountingaccount2->getNomUrl(0,1,1,'',1); - } else { + } else { + print $object->accountancy_code_sell_intra; + } + print ''; + + // Accountancy sell code export + print ''; + print $langs->trans("ProductAccountancySellExportCode"); + print ''; + if (! empty($conf->accounting->enabled)) + { + $accountingaccount3 = new AccountingAccount($db); + $accountingaccount3->fetch('',$object->accountancy_code_sell_export,1); + + print $accountingaccount3->getNomUrl(0,1,1,'',1); + } else { + print $object->accountancy_code_sell_export; + } + print ''; + + // Accountancy buy code + print ''; + print $langs->trans("ProductAccountancyBuyCode"); + print ''; + if (! empty($conf->accounting->enabled)) + { + $accountingaccount4 = new AccountingAccount($db); + $accountingaccount4->fetch('',$object->accountancy_code_buy,1); + + print $accountingaccount4->getNomUrl(0,1,1,'',1); + } else { print $object->accountancy_code_buy; } - print ''; + print ''; // Status (to sell) /* diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index c39b6902edf..5958f94352a 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -8,7 +8,7 @@ * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013-2014 Cedric GROSS * Copyright (C) 2013-2016 Marcos García - * Copyright (C) 2011-2014 Alexandre Spangaro + * Copyright (C) 2011-2017 Alexandre Spangaro * Copyright (C) 2014 Henry Florian * Copyright (C) 2014-2016 Philippe Grand * Copyright (C) 2014 Ion agorria @@ -228,6 +228,8 @@ class Product extends CommonObject public $volume_units; public $accountancy_code_buy; + public $accountancy_code_buy_intra; + public $accountancy_code_buy_export; public $accountancy_code_sell; /** @@ -436,13 +438,15 @@ class Product extends CommonObject $price_min_ttc = price2num($this->price_min * (1 + ($this->tva_tx / 100)),'MU'); } - $this->accountancy_code_buy = trim($this->accountancy_code_buy); + $this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_sell= trim($this->accountancy_code_sell); + $this->accountancy_code_sell_intra= trim($this->accountancy_code_sell_intra); + $this->accountancy_code_sell_export= trim($this->accountancy_code_sell_export); // Barcode value $this->barcode=trim($this->barcode); - // Check parameters + // Check parameters if (empty($this->label)) { $this->error='ErrorMandatoryParametersNotProvided'; @@ -477,19 +481,19 @@ class Product extends CommonObject dol_syslog(get_class($this)."::create ref=".$this->ref." price=".$this->price." price_ttc=".$this->price_ttc." tva_tx=".$this->tva_tx." price_base_type=".$this->price_base_type, LOG_DEBUG); - $now=dol_now(); + $now=dol_now(); $this->db->begin(); - // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts) + // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts) if ($this->barcode == -1) $this->barcode = $this->get_barcode($this,$this->barcode_type_code); // Check more parameters - // If error, this->errors[] is filled - $result = $this->verify(); + // If error, this->errors[] is filled + $result = $this->verify(); - if ($result >= 0) - { + if ($result >= 0) + { $sql = "SELECT count(*) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; $sql.= " WHERE entity IN (".getEntity('product').")"; @@ -519,6 +523,8 @@ class Product extends CommonObject $sql.= ", tosell"; $sql.= ", accountancy_code_buy"; $sql.= ", accountancy_code_sell"; + $sql.= ", accountancy_code_sell_intra"; + $sql.= ", accountancy_code_sell_export"; $sql.= ", canvas"; $sql.= ", finished"; $sql.= ", tobatch"; @@ -540,6 +546,8 @@ class Product extends CommonObject $sql.= ", ".$this->status_buy; $sql.= ", '".$this->db->escape($this->accountancy_code_buy)."'"; $sql.= ", '".$this->db->escape($this->accountancy_code_sell)."'"; + $sql.= ", '".$this->db->escape($this->accountancy_code_sell_intra)."'"; + $sql.= ", '".$this->db->escape($this->accountancy_code_sell_export)."'"; $sql.= ", '".$this->db->escape($this->canvas)."'"; $sql.= ", ".((! isset($this->finished) || $this->finished < 0 || $this->finished == '') ? 'null' : (int) $this->finished); $sql.= ", ".((empty($this->status_batch) || $this->status_batch < 0)? '0':$this->status_batch); @@ -565,25 +573,25 @@ class Product extends CommonObject { if ($this->update($id, $user, true, 'add') <= 0) { - $error++; + $error++; } } else { $error++; - $this->error=$this->db->lasterror(); + $this->error=$this->db->lasterror(); } } else { $error++; - $this->error='ErrorFailedToGetInsertedId'; + $this->error='ErrorFailedToGetInsertedId'; } } else { $error++; - $this->error=$this->db->lasterror(); + $this->error=$this->db->lasterror(); } } else @@ -597,15 +605,15 @@ class Product extends CommonObject else { $error++; - $this->error=$this->db->lasterror(); + $this->error=$this->db->lasterror(); } if (! $error && ! $notrigger) { - // Call trigger - $result=$this->call_trigger('PRODUCT_CREATE',$user); - if ($result < 0) { $error++; } - // End call triggers + // Call trigger + $result=$this->call_trigger('PRODUCT_CREATE',$user); + if ($result < 0) { $error++; } + // End call triggers } if (! $error) @@ -772,6 +780,8 @@ class Product extends CommonObject $this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_sell= trim($this->accountancy_code_sell); + $this->accountancy_code_sell_intra= trim($this->accountancy_code_sell_intra); + $this->accountancy_code_sell_export= trim($this->accountancy_code_sell_export); $this->db->begin(); @@ -883,6 +893,8 @@ class Product extends CommonObject $sql.= ", duration = '" . $this->db->escape($this->duration_value . $this->duration_unit) ."'"; $sql.= ", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy)."'"; $sql.= ", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell)."'"; + $sql.= ", accountancy_code_sell_intra= '" . $this->db->escape($this->accountancy_code_sell_intra)."'"; + $sql.= ", accountancy_code_sell_export= '" . $this->db->escape($this->accountancy_code_sell_export)."'"; $sql.= ", desiredstock = " . ((isset($this->desiredstock) && $this->desiredstock != '') ? $this->desiredstock : "null"); $sql.= ", cost_price = " . ($this->cost_price != '' ? $this->db->escape($this->cost_price) : 'null'); $sql.= ", fk_unit= " . (!$this->fk_unit ? 'NULL' : $this->fk_unit); @@ -1325,7 +1337,7 @@ class Product extends CommonObject * Sets an accountancy code for a product. * Also calls PRODUCT_MODIFY trigger when modified * - * @param string $type It can be 'buy' or 'sell' + * @param string $type It can be 'buy', 'sell', 'sell_intra' or 'sell_export' * @param string $value Accountancy code * @return int <0 KO >0 OK */ @@ -1339,6 +1351,10 @@ class Product extends CommonObject $field = 'accountancy_code_buy'; } elseif ($type == 'sell') { $field = 'accountancy_code_sell'; + } elseif ($type == 'sell_intra') { + $field = 'accountancy_code_sell_intra'; + } elseif ($type == 'sell_export') { + $field = 'accountancy_code_sell_export'; } else { return -1; } @@ -1831,7 +1847,7 @@ class Product extends CommonObject $sql.= " tobuy, fk_product_type, duration, seuil_stock_alerte, canvas, weight, weight_units,"; $sql.= " length, length_units, width, width_units, height, height_units,"; $sql.= " surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,"; - $sql.= " accountancy_code_buy, accountancy_code_sell, stock, pmp,"; + $sql.= " accountancy_code_buy, accountancy_code_sell, accountancy_code_sell_intra, accountancy_code_sell_export, stock, pmp,"; $sql.= " datec, tms, import_key, entity, desiredstock, tobatch, fk_unit,"; $sql.= " fk_price_expression, price_autogen"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; @@ -1850,78 +1866,80 @@ class Product extends CommonObject { $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; - $this->ref = $obj->ref; - $this->ref_ext = $obj->ref_ext; - $this->label = $obj->label; - $this->description = $obj->description; - $this->url = $obj->url; - $this->note_private = $obj->note_private; - $this->note = $obj->note_private; // deprecated + $this->id = $obj->rowid; + $this->ref = $obj->ref; + $this->ref_ext = $obj->ref_ext; + $this->label = $obj->label; + $this->description = $obj->description; + $this->url = $obj->url; + $this->note_private = $obj->note_private; + $this->note = $obj->note_private; // deprecated - $this->type = $obj->fk_product_type; - $this->status = $obj->tosell; - $this->status_buy = $obj->tobuy; - $this->status_batch = $obj->tobatch; + $this->type = $obj->fk_product_type; + $this->status = $obj->tosell; + $this->status_buy = $obj->tobuy; + $this->status_batch = $obj->tobatch; - $this->customcode = $obj->customcode; - $this->country_id = $obj->fk_country; - $this->country_code = getCountry($this->country_id,2,$this->db); - $this->price = $obj->price; - $this->price_ttc = $obj->price_ttc; - $this->price_min = $obj->price_min; - $this->price_min_ttc = $obj->price_min_ttc; - $this->price_base_type = $obj->price_base_type; - $this->cost_price = $obj->cost_price; - $this->default_vat_code = $obj->default_vat_code; - $this->tva_tx = $obj->tva_tx; + $this->customcode = $obj->customcode; + $this->country_id = $obj->fk_country; + $this->country_code = getCountry($this->country_id,2,$this->db); + $this->price = $obj->price; + $this->price_ttc = $obj->price_ttc; + $this->price_min = $obj->price_min; + $this->price_min_ttc = $obj->price_min_ttc; + $this->price_base_type = $obj->price_base_type; + $this->cost_price = $obj->cost_price; + $this->default_vat_code = $obj->default_vat_code; + $this->tva_tx = $obj->tva_tx; //! French VAT NPR - $this->tva_npr = $obj->tva_npr; - $this->recuperableonly = $obj->tva_npr; // For backward compatibility + $this->tva_npr = $obj->tva_npr; + $this->recuperableonly = $obj->tva_npr; // For backward compatibility //! Local taxes - $this->localtax1_tx = $obj->localtax1_tx; - $this->localtax2_tx = $obj->localtax2_tx; - $this->localtax1_type = $obj->localtax1_type; - $this->localtax2_type = $obj->localtax2_type; + $this->localtax1_tx = $obj->localtax1_tx; + $this->localtax2_tx = $obj->localtax2_tx; + $this->localtax1_type = $obj->localtax1_type; + $this->localtax2_type = $obj->localtax2_type; - $this->finished = $obj->finished; - $this->duration = $obj->duration; - $this->duration_value = substr($obj->duration,0,dol_strlen($obj->duration)-1); - $this->duration_unit = substr($obj->duration,-1); - $this->canvas = $obj->canvas; - $this->weight = $obj->weight; - $this->weight_units = $obj->weight_units; - $this->length = $obj->length; - $this->length_units = $obj->length_units; - $this->width = $obj->width; - $this->width_units = $obj->width_units; - $this->height = $obj->height; - $this->height_units = $obj->height_units; + $this->finished = $obj->finished; + $this->duration = $obj->duration; + $this->duration_value = substr($obj->duration,0,dol_strlen($obj->duration)-1); + $this->duration_unit = substr($obj->duration,-1); + $this->canvas = $obj->canvas; + $this->weight = $obj->weight; + $this->weight_units = $obj->weight_units; + $this->length = $obj->length; + $this->length_units = $obj->length_units; + $this->width = $obj->width; + $this->width_units = $obj->width_units; + $this->height = $obj->height; + $this->height_units = $obj->height_units; - $this->surface = $obj->surface; - $this->surface_units = $obj->surface_units; - $this->volume = $obj->volume; - $this->volume_units = $obj->volume_units; - $this->barcode = $obj->barcode; - $this->barcode_type = $obj->fk_barcode_type; + $this->surface = $obj->surface; + $this->surface_units = $obj->surface_units; + $this->volume = $obj->volume; + $this->volume_units = $obj->volume_units; + $this->barcode = $obj->barcode; + $this->barcode_type = $obj->fk_barcode_type; - $this->accountancy_code_buy = $obj->accountancy_code_buy; - $this->accountancy_code_sell = $obj->accountancy_code_sell; + $this->accountancy_code_buy = $obj->accountancy_code_buy; + $this->accountancy_code_sell = $obj->accountancy_code_sell; + $this->accountancy_code_sell_intra = $obj->accountancy_code_sell_intra; + $this->accountancy_code_sell_export = $obj->accountancy_code_sell_export; - $this->seuil_stock_alerte = $obj->seuil_stock_alerte; - $this->desiredstock = $obj->desiredstock; - $this->stock_reel = $obj->stock; - $this->pmp = $obj->pmp; + $this->seuil_stock_alerte = $obj->seuil_stock_alerte; + $this->desiredstock = $obj->desiredstock; + $this->stock_reel = $obj->stock; + $this->pmp = $obj->pmp; - $this->date_creation = $obj->datec; - $this->date_modification = $obj->tms; - $this->import_key = $obj->import_key; - $this->entity = $obj->entity; + $this->date_creation = $obj->datec; + $this->date_modification = $obj->tms; + $this->import_key = $obj->import_key; + $this->entity = $obj->entity; - $this->ref_ext = $obj->ref_ext; - $this->fk_price_expression = $obj->fk_price_expression; - $this->fk_unit = $obj->fk_unit; - $this->price_autogen = $obj->price_autogen; + $this->ref_ext = $obj->ref_ext; + $this->fk_price_expression = $obj->fk_price_expression; + $this->fk_unit = $obj->fk_unit; + $this->price_autogen = $obj->price_autogen; $this->db->free($resql);