12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720 |
- <?php
- /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
- * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
- * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
- * Copyright (C) 2006 Auguria SARL <info@auguria.org>
- * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
- * Copyright (C) 2013-2016 Marcos García <marcosgdf@gmail.com>
- * Copyright (C) 2012-2013 Cédric Salvador <csalvador@gpcsolutions.fr>
- * Copyright (C) 2011-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
- * Copyright (C) 2014 Cédric Gross <c.gross@kreiz-it.fr>
- * Copyright (C) 2014-2015 Ferran Marcet <fmarcet@2byte.es>
- * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
- * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
- * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
- * Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
- * Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
- * Copyright (C) 2019-2021 Frédéric France <frederic.france@netlogic.fr>
- * Copyright (C) 2019-2020 Thibault FOUCART <support@ptibogxiv.net>
- * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/product/card.php
- * \ingroup product
- * \brief Page to show product
- */
- require '../main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
- require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
- require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
- 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';
- require_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.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';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
- require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
- }
- if (!empty($conf->bom->enabled)) {
- require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
- }
- // Load translation files required by the page
- $langs->loadLangs(array('products', 'other'));
- if (!empty($conf->stock->enabled)) {
- $langs->load("stocks");
- }
- if (!empty($conf->facture->enabled)) {
- $langs->load("bills");
- }
- if (!empty($conf->productbatch->enabled)) {
- $langs->load("productbatch");
- }
- $mesg = ''; $error = 0; $errors = array();
- $refalreadyexists = 0;
- $id = GETPOST('id', 'int');
- $ref = (GETPOSTISSET('ref') ? GETPOST('ref', 'alpha') : null);
- $type = (GETPOSTISSET('type') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT);
- $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
- $cancel = GETPOST('cancel', 'alpha');
- $backtopage = GETPOST('backtopage', 'alpha');
- $confirm = GETPOST('confirm', 'alpha');
- $socid = GETPOST('socid', 'int');
- $duration_value = GETPOST('duration_value', 'int');
- $duration_unit = GETPOST('duration_unit', 'alpha');
- $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
- $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra', 'alpha');
- $accountancy_code_sell_export = GETPOST('accountancy_code_sell_export', 'alpha');
- $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
- $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha');
- $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha');
- $checkmandatory = GETPOST('accountancy_code_buy_export', 'alpha');
- // by default 'alphanohtml' (better security); hidden conf MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML allows basic html
- $label_security_check = empty($conf->global->MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML) ? 'alphanohtml' : 'restricthtml';
- if (!empty($user->socid)) {
- $socid = $user->socid;
- }
- // Load object modCodeProduct
- $module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard');
- if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') {
- $module = substr($module, 0, dol_strlen($module) - 4);
- }
- $result = dol_include_once('/core/modules/product/'.$module.'.php');
- if ($result > 0) {
- $modCodeProduct = new $module();
- }
- $object = new Product($db);
- $object->type = $type; // so test later to fill $usercancxxx is correct
- $extrafields = new ExtraFields($db);
- // fetch optionals attributes and labels
- $extrafields->fetch_name_optionals_label($object->table_element);
- if ($id > 0 || !empty($ref)) {
- $result = $object->fetch($id, $ref);
- if ($result < 0) {
- dol_print_error($db, $object->error, $object->errors);
- }
- if (!empty($conf->product->enabled)) {
- $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref);
- } elseif (!empty($conf->service->enabled)) {
- $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref);
- }
- if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { // For backward compatiblity, we scan also old dirs
- if (!empty($conf->product->enabled)) {
- $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos";
- } else {
- $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos";
- }
- }
- }
- $modulepart = 'product';
- // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
- $canvas = !empty($object->canvas) ? $object->canvas : GETPOST("canvas");
- $objcanvas = null;
- if (!empty($canvas)) {
- require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
- $objcanvas = new Canvas($db, $action);
- $objcanvas->getCanvas('product', 'card', $canvas);
- }
- // Security check
- $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
- $fieldtype = (!empty($id) ? 'rowid' : 'ref');
- if ($object->id > 0) {
- if ($object->type == $object::TYPE_PRODUCT) {
- restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
- }
- if ($object->type == $object::TYPE_SERVICE) {
- restrictedArea($user, 'service', $object->id, 'product&product', '', '');
- }
- } else {
- restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
- }
- // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
- $hookmanager->initHooks(array('productcard', 'globalcard'));
- /*
- * Actions
- */
- if ($cancel) {
- $action = '';
- }
- $usercanread = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->lire) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->lire));
- $usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer));
- $usercandelete = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer));
- $createbarcode = empty($conf->barcode->enabled) ? 0 : 1;
- if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->creer_advance)) {
- $createbarcode = 0;
- }
- $parameters = array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
- $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $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)) {
- $backurlforlist = DOL_URL_ROOT.'/product/list.php?type='.$type;
- if (empty($backtopage) || ($cancel && empty($id))) {
- if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
- if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
- $backtopage = $backurlforlist;
- } else {
- $backtopage = DOL_URL_ROOT.'/product/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
- }
- }
- }
- if ($cancel) {
- if (!empty($backtopageforcancel)) {
- header("Location: ".$backtopageforcancel);
- exit;
- } elseif (!empty($backtopage)) {
- header("Location: ".$backtopage);
- exit;
- }
- $action = '';
- }
- // Type
- if ($action == 'setfk_product_type' && $usercancreate) {
- $result = $object->setValueFrom('fk_product_type', GETPOST('fk_product_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY');
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
- exit;
- }
- // Actions to build doc
- $upload_dir = $conf->product->dir_output;
- $permissiontoadd = $usercancreate;
- include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
- include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
- // Barcode type
- if ($action == 'setfk_barcode_type' && $createbarcode) {
- $result = $object->setValueFrom('fk_barcode_type', GETPOST('fk_barcode_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY');
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
- exit;
- }
- // Barcode value
- if ($action == 'setbarcode' && $createbarcode) {
- $result = $object->check_barcode(GETPOST('barcode'), GETPOST('barcode_type_code'));
- if ($result >= 0) {
- $result = $object->setValueFrom('barcode', GETPOST('barcode'), '', null, 'text', '', $user, 'PRODUCT_MODIFY');
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
- exit;
- } else {
- $langs->load("errors");
- if ($result == -1) {
- $errors[] = 'ErrorBadBarCodeSyntax';
- } elseif ($result == -2) {
- $errors[] = 'ErrorBarCodeRequired';
- } elseif ($result == -3) {
- $errors[] = 'ErrorBarCodeAlreadyUsed';
- } else {
- $errors[] = 'FailedToValidateBarCode';
- }
- $error++;
- setEventMessages($errors, null, 'errors');
- }
- }
- // Add a product or service
- if ($action == 'add' && $usercancreate) {
- $error = 0;
- if (!GETPOST('label', $label_security_check)) {
- setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Label')), null, 'errors');
- $action = "create";
- $error++;
- }
- if (empty($ref)) {
- if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
- setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors');
- $action = "create";
- $error++;
- }
- }
- if (!empty($duration_value) && empty($duration_unit)) {
- setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Unit')), null, 'errors');
- $action = "create";
- $error++;
- }
- if (!$error) {
- $units = GETPOST('units', 'int');
- $object->ref = $ref;
- $object->label = GETPOST('label', $label_security_check);
- $object->price_base_type = GETPOST('price_base_type', 'aZ09');
- $object->mandatory_period = !empty(GETPOST("mandatoryperiod", 'alpha')) ? 1 : 0;
- if ($object->price_base_type == 'TTC') {
- $object->price_ttc = GETPOST('price');
- } else {
- $object->price = GETPOST('price');
- }
- if ($object->price_base_type == 'TTC') {
- $object->price_min_ttc = GETPOST('price_min');
- } else {
- $object->price_min = GETPOST('price_min');
- }
- $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
- // We must define tva_tx, npr and local taxes
- $vatratecode = '';
- $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot
- $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
- $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0';
- // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
- $reg = array();
- if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
- // We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in update price.
- $vatratecode = $reg[1];
- // Get record from code
- $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
- $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
- $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
- $sql .= " AND t.code = '".$db->escape($vatratecode)."'";
- $resql = $db->query($sql);
- if ($resql) {
- $obj = $db->fetch_object($resql);
- $npr = $obj->recuperableonly;
- $localtax1 = $obj->localtax1;
- $localtax2 = $obj->localtax2;
- $localtax1_type = $obj->localtax1_type;
- $localtax2_type = $obj->localtax2_type;
- }
- }
- $object->default_vat_code = $vatratecode;
- $object->tva_tx = $tva_tx;
- $object->tva_npr = $npr;
- $object->localtax1_tx = $localtax1;
- $object->localtax2_tx = $localtax2;
- $object->localtax1_type = $localtax1_type;
- $object->localtax2_type = $localtax2_type;
- $object->type = $type;
- $object->status = GETPOST('statut');
- $object->status_buy = GETPOST('statut_buy');
- $object->status_batch = GETPOST('status_batch');
- $object->batch_mask = GETPOST('batch_mask');
- $object->barcode_type = GETPOST('fk_barcode_type');
- $object->barcode = GETPOST('barcode');
- // Set barcode_type_xxx from barcode_type id
- $stdobject = new GenericObject($db);
- $stdobject->element = 'product';
- $stdobject->barcode_type = GETPOST('fk_barcode_type');
- $result = $stdobject->fetch_barcode();
- if ($result < 0) {
- $error++;
- $mesg = 'Failed to get bar code type information ';
- setEventMessages($mesg.$stdobject->error, $mesg.$stdobject->errors, 'errors');
- }
- $object->barcode_type_code = $stdobject->barcode_type_code;
- $object->barcode_type_coder = $stdobject->barcode_type_coder;
- $object->barcode_type_label = $stdobject->barcode_type_label;
- $object->description = dol_htmlcleanlastbr(GETPOST('desc', 'restricthtml'));
- $object->url = GETPOST('url');
- $object->note_private = dol_htmlcleanlastbr(GETPOST('note_private', 'restricthtml'));
- $object->note = $object->note_private; // deprecated
- $object->customcode = GETPOST('customcode', 'alphanohtml');
- $object->country_id = GETPOST('country_id', 'int');
- $object->state_id = GETPOST('state_id', 'int');
- $object->lifetime = GETPOST('lifetime', 'int');
- $object->qc_frequency = GETPOST('qc_frequency', 'int');
- $object->duration_value = $duration_value;
- $object->duration_unit = $duration_unit;
- $object->fk_default_warehouse = GETPOST('fk_default_warehouse');
- $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte') ?GETPOST('seuil_stock_alerte') : 0;
- $object->desiredstock = GETPOST('desiredstock') ?GETPOST('desiredstock') : 0;
- $object->canvas = GETPOST('canvas');
- $object->net_measure = GETPOST('net_measure');
- $object->net_measure_units = GETPOST('net_measure_units'); // This is not the fk_unit but the power of unit
- $object->weight = GETPOST('weight');
- $object->weight_units = GETPOST('weight_units'); // This is not the fk_unit but the power of unit
- $object->length = GETPOST('size');
- $object->length_units = GETPOST('size_units'); // This is not the fk_unit but the power of unit
- $object->width = GETPOST('sizewidth');
- $object->height = GETPOST('sizeheight');
- $object->surface = GETPOST('surface');
- $object->surface_units = GETPOST('surface_units'); // This is not the fk_unit but the power of unit
- $object->volume = GETPOST('volume');
- $object->volume_units = GETPOST('volume_units'); // This is not the fk_unit but the power of unit
- $finished = GETPOST('finished', 'int');
- if ($finished > 0) {
- $object->finished = $finished;
- } else {
- $object->finished = null;
- }
- $units = GETPOST('units', 'int');
- if ($units > 0) {
- $object->fk_unit = $units;
- } else {
- $object->fk_unit = null;
- }
- $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
- $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra', 'alpha');
- $accountancy_code_sell_export = GETPOST('accountancy_code_sell_export', 'alpha');
- $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
- $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha');
- $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha');
- if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
- $object->accountancy_code_sell = '';
- } else {
- $object->accountancy_code_sell = $accountancy_code_sell;
- }
- if (empty($accountancy_code_sell_intra) || $accountancy_code_sell_intra == '-1') {
- $object->accountancy_code_sell_intra = '';
- } else {
- $object->accountancy_code_sell_intra = $accountancy_code_sell_intra;
- }
- if (empty($accountancy_code_sell_export) || $accountancy_code_sell_export == '-1') {
- $object->accountancy_code_sell_export = '';
- } else {
- $object->accountancy_code_sell_export = $accountancy_code_sell_export;
- }
- if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
- $object->accountancy_code_buy = '';
- } else {
- $object->accountancy_code_buy = $accountancy_code_buy;
- }
- if (empty($accountancy_code_buy_intra) || $accountancy_code_buy_intra == '-1') {
- $object->accountancy_code_buy_intra = '';
- } else {
- $object->accountancy_code_buy_intra = $accountancy_code_buy_intra;
- }
- if (empty($accountancy_code_buy_export) || $accountancy_code_buy_export == '-1') {
- $object->accountancy_code_buy_export = '';
- } else {
- $object->accountancy_code_buy_export = $accountancy_code_buy_export;
- }
- // MultiPrix
- if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
- for ($i = 2; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
- if (GETPOSTISSET("price_".$i)) {
- $object->multiprices["$i"] = price2num(GETPOST("price_".$i), 'MU');
- $object->multiprices_base_type["$i"] = GETPOST("multiprices_base_type_".$i);
- } else {
- $object->multiprices["$i"] = "";
- }
- }
- }
- // Fill array 'array_options' with data from add form
- $ret = $extrafields->setOptionalsFromPost(null, $object);
- if ($ret < 0) {
- $error++;
- }
- if (!$ref && !empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
- // Generate ref...
- $ref = $modCodeProduct->getNextValue($object, $type);
- }
- if (!$error) {
- $id = $object->create($user);
- }
- if ($id > 0) {
- // Category association
- $categories = GETPOST('categories', 'array');
- $object->setCategories($categories);
- if (!empty($backtopage)) {
- $backtopage = preg_replace('/__ID__/', $object->id, $backtopage); // New method to autoselect project after a New on another form object creation
- if (preg_match('/\?/', $backtopage)) {
- $backtopage .= '&socid='.$object->id; // Old method
- }
- header("Location: ".$backtopage);
- exit;
- } else {
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
- exit;
- }
- } else {
- if (count($object->errors)) {
- setEventMessages($object->error, $object->errors, 'errors');
- } else {
- setEventMessages($langs->trans($object->error), null, 'errors');
- }
- $action = "create";
- }
- }
- }
- // Update a product or service
- if ($action == 'update' && $usercancreate) {
- if (GETPOST('cancel', 'alpha')) {
- $action = '';
- } else {
- if ($object->id > 0) {
- $object->oldcopy = clone $object;
- if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
- $object->ref = $ref;
- }
- $object->label = GETPOST('label', $label_security_check);
- $desc = dol_htmlcleanlastbr(preg_replace('/ $/', '', GETPOST('desc', 'restricthtml')));
- $object->description = $desc;
- $object->url = GETPOST('url');
- if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
- $object->note_private = dol_htmlcleanlastbr(GETPOST('note_private', 'restricthtml'));
- $object->note = $object->note_private;
- }
- $object->customcode = GETPOST('customcode', 'alpha');
- $object->country_id = GETPOST('country_id', 'int');
- $object->state_id = GETPOST('state_id', 'int');
- $object->lifetime = GETPOST('lifetime', 'int');
- $object->qc_frequency = GETPOST('qc_frequency', 'int');
- $object->status = GETPOST('statut', 'int');
- $object->status_buy = GETPOST('statut_buy', 'int');
- $object->status_batch = GETPOST('status_batch', 'aZ09');
- $object->batch_mask = GETPOST('batch_mask', 'alpha');
- $object->fk_default_warehouse = GETPOST('fk_default_warehouse');
- // removed from update view so GETPOST always empty
- /*
- $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte');
- $object->desiredstock = GETPOST('desiredstock');
- */
- $object->duration_value = GETPOST('duration_value', 'int');
- $object->duration_unit = GETPOST('duration_unit', 'alpha');
- $object->canvas = GETPOST('canvas');
- $object->net_measure = GETPOST('net_measure');
- $object->net_measure_units = GETPOST('net_measure_units'); // This is not the fk_unit but the power of unit
- $object->weight = GETPOST('weight');
- $object->weight_units = GETPOST('weight_units'); // This is not the fk_unit but the power of unit
- $object->length = GETPOST('size');
- $object->length_units = GETPOST('size_units'); // This is not the fk_unit but the power of unit
- $object->width = GETPOST('sizewidth');
- $object->height = GETPOST('sizeheight');
- $object->surface = GETPOST('surface');
- $object->surface_units = GETPOST('surface_units'); // This is not the fk_unit but the power of unit
- $object->volume = GETPOST('volume');
- $object->volume_units = GETPOST('volume_units'); // This is not the fk_unit but the power of unit
- $finished = GETPOST('finished', 'int');
- if ($finished >= 0) {
- $object->finished = $finished;
- } else {
- $object->finished = null;
- }
- $fk_default_bom = GETPOST('fk_default_bom', 'int');
- if ($fk_default_bom >= 0) {
- $object->fk_default_bom = $fk_default_bom;
- } else {
- $object->fk_default_bom = null;
- }
- $units = GETPOST('units', 'int');
- if ($units > 0) {
- $object->fk_unit = $units;
- } else {
- $object->fk_unit = null;
- }
- $object->barcode_type = GETPOST('fk_barcode_type');
- $object->barcode = GETPOST('barcode');
- // Set barcode_type_xxx from barcode_type id
- $stdobject = new GenericObject($db);
- $stdobject->element = 'product';
- $stdobject->barcode_type = GETPOST('fk_barcode_type');
- $result = $stdobject->fetch_barcode();
- if ($result < 0) {
- $error++;
- $mesg = 'Failed to get bar code type information ';
- setEventMessages($mesg.$stdobject->error, $mesg.$stdobject->errors, 'errors');
- }
- $object->barcode_type_code = $stdobject->barcode_type_code;
- $object->barcode_type_coder = $stdobject->barcode_type_coder;
- $object->barcode_type_label = $stdobject->barcode_type_label;
- $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
- $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra', 'alpha');
- $accountancy_code_sell_export = GETPOST('accountancy_code_sell_export', 'alpha');
- $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
- $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha');
- $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha');
- $checkmandatory = GETPOST('mandatoryperiod', 'alpha');
- if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
- $object->accountancy_code_sell = '';
- } else {
- $object->accountancy_code_sell = $accountancy_code_sell;
- }
- if (empty($accountancy_code_sell_intra) || $accountancy_code_sell_intra == '-1') {
- $object->accountancy_code_sell_intra = '';
- } else {
- $object->accountancy_code_sell_intra = $accountancy_code_sell_intra;
- }
- if (empty($accountancy_code_sell_export) || $accountancy_code_sell_export == '-1') {
- $object->accountancy_code_sell_export = '';
- } else {
- $object->accountancy_code_sell_export = $accountancy_code_sell_export;
- }
- if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
- $object->accountancy_code_buy = '';
- } else {
- $object->accountancy_code_buy = $accountancy_code_buy;
- }
- if (empty($accountancy_code_buy_intra) || $accountancy_code_buy_intra == '-1') {
- $object->accountancy_code_buy_intra = '';
- } else {
- $object->accountancy_code_buy_intra = $accountancy_code_buy_intra;
- }
- if (empty($accountancy_code_buy_export) || $accountancy_code_buy_export == '-1') {
- $object->accountancy_code_buy_export = '';
- } else {
- $object->accountancy_code_buy_export = $accountancy_code_buy_export;
- }
- if ($object->isService()) {
- $object->mandatory_period = (!empty($checkmandatory)) ? 1 : 0 ;
- }
- // Fill array 'array_options' with data from add form
- $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
- if ($ret < 0) {
- $error++;
- }
- if (!$error && $object->check()) {
- if ($object->update($object->id, $user) > 0) {
- // Category association
- $categories = GETPOST('categories', 'array');
- $object->setCategories($categories);
- $action = 'view';
- } else {
- if (count($object->errors)) {
- setEventMessages($object->error, $object->errors, 'errors');
- } else {
- setEventMessages($langs->trans($object->error), null, 'errors');
- }
- $action = 'edit';
- }
- } else {
- if (count($object->errors)) {
- setEventMessages($object->error, $object->errors, 'errors');
- } else {
- setEventMessages($langs->trans("ErrorProductBadRefOrLabel"), null, 'errors');
- }
- $action = 'edit';
- }
- }
- }
- }
- // Action clone object
- if ($action == 'confirm_clone' && $confirm != 'yes') {
- $action = '';
- }
- if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) {
- if (!GETPOST('clone_content') && !GETPOST('clone_prices')) {
- setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
- } else {
- $db->begin();
- $originalId = $id;
- if ($object->id > 0) {
- $object->ref = GETPOST('clone_ref', 'alphanohtml');
- $object->status = 0;
- $object->status_buy = 0;
- $object->id = null;
- $object->barcode = -1;
- if ($object->check()) {
- $object->context['createfromclone'] = 'createfromclone';
- $id = $object->create($user);
- if ($id > 0) {
- if (GETPOST('clone_composition')) {
- $result = $object->clone_associations($originalId, $id);
- if ($result < 1) {
- $db->rollback();
- setEventMessages($langs->trans('ErrorProductClone'), null, 'errors');
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$originalId);
- exit;
- }
- }
- if (GETPOST('clone_categories')) {
- $result = $object->cloneCategories($originalId, $id);
- if ($result < 1) {
- $db->rollback();
- setEventMessages($langs->trans('ErrorProductClone'), null, 'errors');
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$originalId);
- exit;
- }
- }
- if (GETPOST('clone_prices')) {
- $result = $object->clone_price($originalId, $id);
- if ($result < 1) {
- $db->rollback();
- setEventMessages($langs->trans('ErrorProductClone'), null, 'errors');
- header('Location: '.$_SERVER['PHP_SELF'].'?id='.$originalId);
- exit();
- }
- }
- // $object->clone_fournisseurs($originalId, $id);
- $db->commit();
- $db->close();
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
- exit;
- } else {
- $id = $originalId;
- if ($object->error == 'ErrorProductAlreadyExists') {
- $db->rollback();
- $refalreadyexists++;
- $action = "";
- $mesg = $langs->trans("ErrorProductAlreadyExists", $object->ref);
- $mesg .= ' <a href="'.$_SERVER["PHP_SELF"].'?ref='.$object->ref.'">'.$langs->trans("ShowCardHere").'</a>.';
- setEventMessages($mesg, null, 'errors');
- $object->fetch($id);
- } else {
- $db->rollback();
- if (count($object->errors)) {
- setEventMessages($object->error, $object->errors, 'errors');
- dol_print_error($db, $object->errors);
- } else {
- setEventMessages($langs->trans($object->error), null, 'errors');
- dol_print_error($db, $object->error);
- }
- }
- }
- unset($object->context['createfromclone']);
- }
- } else {
- $db->rollback();
- dol_print_error($db, $object->error);
- }
- }
- }
- // Delete a product
- if ($action == 'confirm_delete' && $confirm != 'yes') {
- $action = '';
- }
- if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) {
- $result = $object->delete($user);
- if ($result > 0) {
- header('Location: '.DOL_URL_ROOT.'/product/list.php?type='.$object->type.'&delprod='.urlencode($object->ref));
- exit;
- } else {
- setEventMessages($langs->trans($object->error), null, 'errors');
- $reload = 0;
- $action = '';
- }
- }
- // Add product into object
- if ($object->id > 0 && $action == 'addin') {
- $thirpdartyid = 0;
- if (GETPOST('propalid') > 0) {
- $propal = new Propal($db);
- $result = $propal->fetch(GETPOST('propalid'));
- if ($result <= 0) {
- dol_print_error($db, $propal->error);
- exit;
- }
- $thirpdartyid = $propal->socid;
- } elseif (GETPOST('commandeid') > 0) {
- $commande = new Commande($db);
- $result = $commande->fetch(GETPOST('commandeid'));
- if ($result <= 0) {
- dol_print_error($db, $commande->error);
- exit;
- }
- $thirpdartyid = $commande->socid;
- } elseif (GETPOST('factureid') > 0) {
- $facture = new Facture($db);
- $result = $facture->fetch(GETPOST('factureid'));
- if ($result <= 0) {
- dol_print_error($db, $facture->error);
- exit;
- }
- $thirpdartyid = $facture->socid;
- }
- if ($thirpdartyid > 0) {
- $soc = new Societe($db);
- $result = $soc->fetch($thirpdartyid);
- if ($result <= 0) {
- dol_print_error($db, $soc->error);
- exit;
- }
- $desc = $object->description;
- $tva_tx = get_default_tva($mysoc, $soc, $object->id);
- $tva_npr = get_default_npr($mysoc, $soc, $object->id);
- if (empty($tva_tx)) {
- $tva_npr = 0;
- }
- $localtax1_tx = get_localtax($tva_tx, 1, $soc, $mysoc, $tva_npr);
- $localtax2_tx = get_localtax($tva_tx, 2, $soc, $mysoc, $tva_npr);
- $pu_ht = $object->price;
- $pu_ttc = $object->price_ttc;
- $price_base_type = $object->price_base_type;
- // If multiprice
- if ($conf->global->PRODUIT_MULTIPRICES && $soc->price_level) {
- $pu_ht = $object->multiprices[$soc->price_level];
- $pu_ttc = $object->multiprices_ttc[$soc->price_level];
- $price_base_type = $object->multiprices_base_type[$soc->price_level];
- } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
- require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
- $prodcustprice = new Productcustomerprice($db);
- $filter = array('t.fk_product' => $object->id, 't.fk_soc' => $soc->id);
- $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
- if ($result) {
- if (count($prodcustprice->lines) > 0) {
- $pu_ht = price($prodcustprice->lines [0]->price);
- $pu_ttc = price($prodcustprice->lines [0]->price_ttc);
- $price_base_type = $prodcustprice->lines [0]->price_base_type;
- $tva_tx = $prodcustprice->lines [0]->tva_tx;
- }
- }
- }
- $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
- $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
- // On reevalue prix selon taux tva car taux tva transaction peut etre different
- // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
- if ($tmpvat != $tmpprodvat) {
- if ($price_base_type != 'HT') {
- $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
- } else {
- $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
- }
- }
- if (GETPOST('propalid') > 0) {
- // Define cost price for margin calculation
- $buyprice = 0;
- if (($result = $propal->defineBuyPrice($pu_ht, price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) {
- dol_syslog($langs->trans('FailedToGetCostPrice'));
- setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors');
- } else {
- $buyprice = $result;
- }
- $result = $propal->addline(
- $desc,
- $pu_ht,
- price2num(GETPOST('qty'), 'MS'),
- $tva_tx,
- $localtax1_tx, // localtax1
- $localtax2_tx, // localtax2
- $object->id,
- price2num(GETPOST('remise_percent'), '', 2),
- $price_base_type,
- $pu_ttc,
- 0,
- 0,
- -1,
- 0,
- 0,
- 0,
- $buyprice,
- '',
- '',
- '',
- 0,
- $object->fk_unit
- );
- if ($result > 0) {
- header("Location: ".DOL_URL_ROOT."/comm/propal/card.php?id=".$propal->id);
- return;
- }
- setEventMessages($langs->trans("ErrorUnknown").": $result", null, 'errors');
- } elseif (GETPOST('commandeid') > 0) {
- // Define cost price for margin calculation
- $buyprice = 0;
- if (($result = $commande->defineBuyPrice($pu_ht, price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) {
- dol_syslog($langs->trans('FailedToGetCostPrice'));
- setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors');
- } else {
- $buyprice = $result;
- }
- $result = $commande->addline(
- $desc,
- $pu_ht,
- price2num(GETPOST('qty'), 'MS'),
- $tva_tx,
- $localtax1_tx, // localtax1
- $localtax2_tx, // localtax2
- $object->id,
- price2num(GETPOST('remise_percent'), '', 2),
- '',
- '',
- $price_base_type,
- $pu_ttc,
- '',
- '',
- 0,
- -1,
- 0,
- 0,
- null,
- $buyprice,
- '',
- 0,
- $object->fk_unit
- );
- if ($result > 0) {
- header("Location: ".DOL_URL_ROOT."/commande/card.php?id=".urlencode($commande->id));
- exit;
- }
- } elseif (GETPOST('factureid') > 0) {
- // Define cost price for margin calculation
- $buyprice = 0;
- if (($result = $facture->defineBuyPrice($pu_ht, price2num(GETPOST('remise_percent'), '', 2), $object->id)) < 0) {
- dol_syslog($langs->trans('FailedToGetCostPrice'));
- setEventMessages($langs->trans('FailedToGetCostPrice'), null, 'errors');
- } else {
- $buyprice = $result;
- }
- $result = $facture->addline(
- $desc,
- $pu_ht,
- price2num(GETPOST('qty'), 'MS'),
- $tva_tx,
- $localtax1_tx,
- $localtax2_tx,
- $object->id,
- price2num(GETPOST('remise_percent'), '', 2),
- '',
- '',
- '',
- '',
- '',
- $price_base_type,
- $pu_ttc,
- Facture::TYPE_STANDARD,
- -1,
- 0,
- '',
- 0,
- 0,
- null,
- $buyprice,
- '',
- 0,
- 100,
- '',
- $object->fk_unit
- );
- if ($result > 0) {
- header("Location: ".DOL_URL_ROOT."/compta/facture/card.php?facid=".$facture->id);
- exit;
- }
- }
- } else {
- $action = "";
- setEventMessages($langs->trans("WarningSelectOneDocument"), null, 'warnings');
- }
- }
- }
- /*
- * View
- */
- $form = new Form($db);
- $formfile = new FormFile($db);
- $formproduct = new FormProduct($db);
- $formcompany = new FormCompany($db);
- if (!empty($conf->accounting->enabled)) {
- $formaccounting = new FormAccounting($db);
- }
- $title = $langs->trans('ProductServiceCard');
- $help_url = '';
- $shortlabel = dol_trunc($object->label, 16);
- if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
- $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Card');
- $help_url = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos|DE:Modul_Produkte';
- }
- if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
- $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Card');
- $help_url = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios|DE:Modul_Leistungen';
- }
- llxHeader('', $title, $help_url);
- // Load object modBarCodeProduct
- $res = 0;
- if (!empty($conf->barcode->enabled) && !empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) {
- $module = strtolower($conf->global->BARCODE_PRODUCT_ADDON_NUM);
- $dirbarcode = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']);
- foreach ($dirbarcode as $dirroot) {
- $res = dol_include_once($dirroot.$module.'.php');
- if ($res) {
- break;
- }
- }
- if ($res > 0) {
- $modBarCodeProduct = new $module();
- }
- }
- if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
- // -----------------------------------------
- // When used with CANVAS
- // -----------------------------------------
- if (empty($object->error) && $id) {
- $result = $object->fetch($id);
- if ($result <= 0) {
- dol_print_error('', $object->error);
- }
- }
- $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
- $objcanvas->display_canvas($action); // Show template
- } else {
- // -----------------------------------------
- // When used in standard mode
- // -----------------------------------------
- if ($action == 'create' && $usercancreate) {
- //WYSIWYG Editor
- require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
- if (!empty($conf->use_javascript_ajax)) {
- print '<script type="text/javascript">';
- print '$(document).ready(function () {
- $("#selectcountry_id").change(function() {
- document.formprod.action.value="create";
- document.formprod.submit();
- });
- });';
- print '</script>'."\n";
- }
- // Load object modCodeProduct
- $module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard');
- if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') {
- $module = substr($module, 0, dol_strlen($module) - 4);
- }
- $result = dol_include_once('/core/modules/product/'.$module.'.php');
- if ($result > 0) {
- $modCodeProduct = new $module();
- }
- dol_set_focus('input[name="ref"]');
- print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formprod">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="add">';
- print '<input type="hidden" name="type" value="'.$type.'">'."\n";
- if (!empty($modCodeProduct->code_auto)) {
- print '<input type="hidden" name="code_auto" value="1">';
- }
- if (!empty($modBarCodeProduct->code_auto)) {
- print '<input type="hidden" name="barcode_auto" value="1">';
- }
- print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
- if ($type == 1) {
- $picto = 'service';
- $title = $langs->trans("NewService");
- } else {
- $picto = 'product';
- $title = $langs->trans("NewProduct");
- }
- $linkback = "";
- print load_fiche_titre($title, $linkback, $picto);
- // We set country_id, country_code and country for the selected country
- $object->country_id = GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : null;
- if ($object->country_id > 0) {
- $tmparray = getCountry($object->country_id, 'all');
- $object->country_code = $tmparray['code'];
- $object->country = $tmparray['label'];
- }
- print dol_get_fiche_head('');
- print '<table class="border centpercent">';
- if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
- print '<tr>';
- $tmpcode = '';
- if (!empty($modCodeProduct->code_auto)) {
- $tmpcode = $modCodeProduct->getNextValue($object, $type);
- }
- print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input id="ref" name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag(GETPOSTISSET('ref') ? GETPOST('ref', 'alphanohtml') : $tmpcode).'">';
- if ($refalreadyexists) {
- print $langs->trans("RefAlreadyExists");
- }
- print '</td></tr>';
- }
- // Label
- print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth300 maxwidth400onsmartphone" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label', $label_security_check)).'"></td></tr>';
- // On sell
- print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
- $statutarray = array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
- print $form->selectarray('statut', $statutarray, GETPOST('statut'));
- print '</td></tr>';
- // To buy
- print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
- $statutarray = array('1' => $langs->trans("ProductStatusOnBuy"), '0' => $langs->trans("ProductStatusNotOnBuy"));
- print $form->selectarray('statut_buy', $statutarray, GETPOST('statut_buy'));
- print '</td></tr>';
- // Batch number management
- if (!empty($conf->productbatch->enabled)) {
- print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td>';
- $statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"), '2' => $langs->trans("ProductStatusOnSerial"));
- print $form->selectarray('status_batch', $statutarray, GETPOST('status_batch'));
- print '</td></tr>';
- // Product specific batch number management
- $status_batch = GETPOST('status_batch');
- if ($status_batch !== '0') {
- $langs->load("admin");
- $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
- $tooltip .= '<br>'.$langs->trans("GenericMaskCodes2");
- $tooltip .= '<br>'.$langs->trans("GenericMaskCodes3");
- $tooltip .= '<br>'.$langs->trans("GenericMaskCodes4a", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
- $tooltip .= '<br>'.$langs->trans("GenericMaskCodes5");
- if (($conf->global->PRODUCTBATCH_LOT_USE_PRODUCT_MASKS && $conf->global->PRODUCTBATCH_LOT_ADDON == 'mod_lot_advanced')
- || ($conf->global->PRODUCTBATCH_SN_USE_PRODUCT_MASKS && $conf->global->PRODUCTBATCH_SN_ADDON == 'mod_sn_advanced')) {
- print '<tr><td id="mask_option">'.$langs->trans("ManageLotMask").'</td>';
- $inherited_mask_lot = $conf->global->LOT_ADVANCED_MASK;
- $inherited_mask_sn = $conf->global->SN_ADVANCED_MASK;
- print '<td id="field_mask">';
- print $form->textwithpicto('<input type="text" class="flat minwidth175" name="batch_mask" id="batch_mask_input">', $tooltip, 1, 1);
- print '<script type="text/javascript">
- $(document).ready(function() {
- $("#field_mask, #mask_option").addClass("hideobject");
- $("#status_batch").on("change", function () {
- console.log("We change batch status");
- var optionSelected = $("option:selected", this);
- var valueSelected = this.value;
- $("#field_mask, #mask_option").addClass("hideobject");
- ';
- if ($conf->global->PRODUCTBATCH_LOT_USE_PRODUCT_MASKS && $conf->global->PRODUCTBATCH_LOT_ADDON == 'mod_lot_advanced') {
- print '
- if (this.value == 1) {
- $("#field_mask, #mask_option").toggleClass("hideobject");
- $("#batch_mask_input").val("'.$inherited_mask_lot.'");
- }
- ';
- }
- if ($conf->global->PRODUCTBATCH_SN_USE_PRODUCT_MASKS && $conf->global->PRODUCTBATCH_SN_ADDON == 'mod_sn_advanced') {
- print '
- if (this.value == 2) {
- $("#field_mask, #mask_option").toggleClass("hideobject");
- $("#batch_mask_input").val("'.$inherited_mask_sn.'");
- }
- ';
- }
- print '
- })
- })
- </script>';
- print '</td></tr>';
- }
- }
- }
- $showbarcode = empty($conf->barcode->enabled) ? 0 : 1;
- if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
- $showbarcode = 0;
- }
- if ($showbarcode) {
- print '<tr><td>'.$langs->trans('BarcodeType').'</td><td>';
- if (GETPOSTISSET('fk_barcode_type')) {
- $fk_barcode_type = GETPOST('fk_barcode_type');
- } else {
- if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) {
- $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
- }
- }
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
- $formbarcode = new FormBarCode($db);
- print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
- print '</td>';
- print '</tr><tr>';
- print '<td>'.$langs->trans("BarcodeValue").'</td><td>';
- $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
- if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) {
- $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type);
- }
- print '<input class="maxwidth100" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
- print '</td></tr>';
- }
- // Description (used in invoice, propal...)
- print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
- $doleditor = new DolEditor('desc', GETPOST('desc', 'restricthtml'), '', 160, 'dolibarr_details', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_4, '90%');
- $doleditor->Create();
- print "</td></tr>";
- if (empty($conf->global->PRODUCT_DISABLE_PUBLIC_URL)) {
- // Public URL
- print '<tr><td>'.$langs->trans("PublicUrl").'</td><td>';
- print img_picto('', 'globe', 'class="pictofixedwidth"');
- print '<input type="text" name="url" class="quatrevingtpercent" value="'.GETPOST('url').'">';
- print '</td></tr>';
- }
- if ($type != 1 && !empty($conf->stock->enabled)) {
- // Default warehouse
- print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
- print img_picto($langs->trans("DefaultWarehouse"), 'stock', 'class="pictofixedwidth"');
- print $formproduct->selectWarehouses(GETPOST('fk_default_warehouse', 'int'), 'fk_default_warehouse', 'warehouseopen', 1, 0, 0, '', 0, 0, array(), 'minwidth300 widthcentpercentminusxx maxwidth500');
- print ' <a href="'.DOL_URL_ROOT.'/product/stock/card.php?action=create&token='.newToken().'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken()).'">';
- print '<span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddWarehouse").'"></span>';
- print '</a>';
- print '</td>';
- print '</tr>';
- if (empty($conf->global->PRODUCT_DISABLE_STOCK_LEVELS)) {
- // Stock min level
- print '<tr><td>'.$form->textwithpicto($langs->trans("StockLimit"), $langs->trans("StockLimitDesc"), 1).'</td><td>';
- print '<input name="seuil_stock_alerte" class="maxwidth50" value="'.GETPOST('seuil_stock_alerte').'">';
- print '</td>';
- print '</tr>';
- // Stock desired level
- print '<tr><td>'.$form->textwithpicto($langs->trans("DesiredStock"), $langs->trans("DesiredStockDesc"), 1).'</td><td>';
- print '<input name="desiredstock" class="maxwidth50" value="'.GETPOST('desiredstock').'">';
- print '</td></tr>';
- }
- } else {
- if (empty($conf->global->PRODUCT_DISABLE_STOCK_LEVELS)) {
- print '<input name="seuil_stock_alerte" type="hidden" value="0">';
- print '<input name="desiredstock" type="hidden" value="0">';
- }
- }
- // Duration
- if ($type == 1) {
- print '<tr><td>'.$langs->trans("Duration").'</td><td>';
- print '<input name="duration_value" size="4" value="'.GETPOST('duration_value', 'int').'">';
- print $formproduct->selectMeasuringUnits("duration_unit", "time", (GETPOSTISSET('duration_value') ? GETPOSTISSET('duration_value', 'alpha') : 'h'), 0, 1);
- // Mandatory period
- print ' ';
- print '<input type="checkbox" id="mandatoryperiod" name="mandatoryperiod"'.($object->mandatory_period == 1 ? ' checked="checked"' : '').'>';
- print '<label for="mandatoryperiod">';
- $htmltooltip = $langs->trans("mandatoryHelper");
- print $form->textwithpicto($langs->trans("mandatoryperiod"), $htmltooltip, 1, 0);
- print '</label>';
- print '</td></tr>';
- }
- if ($type != 1) { // Nature, Weight and volume only applies to products and not to services
- if (empty($conf->global->PRODUCT_DISABLE_NATURE)) {
- // Nature
- print '<tr><td>'.$form->textwithpicto($langs->trans("NatureOfProductShort"), $langs->trans("NatureOfProductDesc")).'</td><td>';
- print $formproduct->selectProductNature('finished', $object->finished);
- print '</td></tr>';
- }
- }
- if ($type != 1) {
- if (empty($conf->global->PRODUCT_DISABLE_WEIGHT)) {
- // Brut Weight
- print '<tr><td>'.$langs->trans("Weight").'</td><td>';
- print '<input name="weight" size="4" value="'.GETPOST('weight').'">';
- print $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOSTISSET('weight_units') ?GETPOST('weight_units', 'alpha') : (empty($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? 0 : $conf->global->MAIN_WEIGHT_DEFAULT_UNIT), 0, 2);
- print '</td></tr>';
- }
- // Brut Length
- if (empty($conf->global->PRODUCT_DISABLE_SIZE)) {
- print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td>';
- print '<input name="size" class="width50" value="'.GETPOST('size').'"> x ';
- print '<input name="sizewidth" class="width50" value="'.GETPOST('sizewidth').'"> x ';
- print '<input name="sizeheight" class="width50" value="'.GETPOST('sizeheight').'">';
- print $formproduct->selectMeasuringUnits("size_units", "size", GETPOSTISSET('size_units') ?GETPOST('size_units', 'alpha') : '0', 0, 2);
- print '</td></tr>';
- }
- if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) {
- // Brut Surface
- print '<tr><td>'.$langs->trans("Surface").'</td><td>';
- print '<input name="surface" size="4" value="'.GETPOST('surface').'">';
- print $formproduct->selectMeasuringUnits("surface_units", "surface", GETPOSTISSET('surface_units') ?GETPOST('surface_units', 'alpha') : '0', 0, 2);
- print '</td></tr>';
- }
- if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) {
- // Brut Volume
- print '<tr><td>'.$langs->trans("Volume").'</td><td>';
- print '<input name="volume" size="4" value="'.GETPOST('volume').'">';
- print $formproduct->selectMeasuringUnits("volume_units", "volume", GETPOSTISSET('volume_units') ?GETPOST('volume_units', 'alpha') : '0', 0, 2);
- print '</td></tr>';
- }
- if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) {
- // Net Measure
- print '<tr><td>'.$langs->trans("NetMeasure").'</td><td>';
- print '<input name="net_measure" size="4" value="'.GETPOST('net_measure').'">';
- print $formproduct->selectMeasuringUnits("net_measure_units", '', GETPOSTISSET('net_measure_units') ?GETPOST('net_measure_units', 'alpha') : (empty($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? 0 : $conf->global->MAIN_WEIGHT_DEFAULT_UNIT), 0, 0);
- print '</td></tr>';
- }
- }
- // Units
- if (!empty($conf->global->PRODUCT_USE_UNITS)) {
- print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td>';
- print '<td>';
- print $form->selectUnits(empty($line->fk_unit) ? $conf->global->PRODUCT_USE_UNITS : $line->fk_unit, 'units');
- print '</td></tr>';
- }
- // Custom code
- if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO) && empty($type)) {
- print '<tr><td class="wordbreak">'.$langs->trans("CustomCode").'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.GETPOST('customcode').'"></td></tr>';
- // Origin country
- print '<tr><td>'.$langs->trans("CountryOrigin").'</td>';
- print '<td>';
- print img_picto('', 'globe-americas', 'class="paddingrightonly"');
- print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth300 widthcentpercentminusx maxwidth500');
- if ($user->admin) {
- print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
- }
- print '</td></tr>';
- // State
- if (empty($conf->global->PRODUCT_DISABLE_STATE)) {
- print '<tr>';
- if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) {
- print '<td>'.$form->editfieldkey('RegionStateOrigin', 'state_id', '', $object, 0).'</td><td>';
- } else {
- print '<td>'.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).'</td><td>';
- }
- print img_picto('', 'state', 'class="pictofixedwidth"');
- print $formcompany->select_state($object->state_id, $object->country_code);
- print '</tr>';
- }
- }
- // Quality control
- if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
- print '<tr><td>'.$langs->trans("LifeTime").'</td><td><input name="lifetime" class="maxwidth100onsmartphone" value="'.GETPOST('lifetime').'"></td></tr>';
- print '<tr><td>'.$langs->trans("QCFrequency").'</td><td><input name="qc_frequency" class="maxwidth100onsmartphone" value="'.GETPOST('qc_frequency').'"></td></tr>';
- }
- // Other attributes
- $parameters = array('colspan' => ' colspan="2"', 'cols'=>2);
- $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- if (empty($reshook)) {
- print $object->showOptionals($extrafields, 'create', $parameters);
- }
- // Note (private, no output on invoices, propales...)
- //if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) available in create mode
- //{
- print '<tr><td class="tdtop">'.$langs->trans("NoteNotVisibleOnBill").'</td><td>';
- // We use dolibarr_details as type of DolEditor here, because we must not accept images as description is included into PDF and not accepted by TCPDF.
- $doleditor = new DolEditor('note_private', GETPOST('note_private', 'restricthtml'), '', 140, 'dolibarr_details', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_PRODUCTDESC'), ROWS_8, '90%');
- $doleditor->Create();
- print "</td></tr>";
- //}
- if (!empty($conf->categorie->enabled)) {
- // Categories
- print '<tr><td>'.$langs->trans("Categories").'</td><td>';
- $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1);
- print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
- print "</td></tr>";
- }
- print '</table>';
- print '<hr>';
- if (empty($conf->global->PRODUCT_DISABLE_PRICES)) {
- if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
- // We do no show price array on create when multiprices enabled.
- // We must set them on prices tab.
- print '<table class="border centpercent">';
- // VAT
- print '<tr><td class="titlefieldcreate">'.$langs->trans("VATRate").'</td><td>';
- $defaultva = get_default_tva($mysoc, $mysoc);
- print $form->load_tva("tva_tx", $defaultva, $mysoc, $mysoc, 0, 0, '', false, 1);
- print '</td></tr>';
- print '</table>';
- print '<br>';
- } else {
- print '<table class="border centpercent">';
- // Price
- print '<tr><td class="titlefieldcreate">'.$langs->trans("SellingPrice").'</td>';
- print '<td><input name="price" class="maxwidth50" value="'.$object->price.'">';
- print $form->selectPriceBaseType($conf->global->PRODUCT_PRICE_BASE_TYPE, "price_base_type");
- print '</td></tr>';
- // Min price
- print '<tr><td>'.$langs->trans("MinPrice").'</td>';
- print '<td><input name="price_min" class="maxwidth50" value="'.$object->price_min.'">';
- print '</td></tr>';
- // VAT
- print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
- $defaultva = get_default_tva($mysoc, $mysoc);
- print $form->load_tva("tva_tx", $defaultva, $mysoc, $mysoc, 0, 0, '', false, 1);
- print '</td></tr>';
- print '</table>';
- print '<br>';
- }
- }
- // Accountancy codes
- print '<!-- accountancy codes -->'."\n";
- print '<table class="border centpercent">';
- if (empty($conf->global->PRODUCT_DISABLE_ACCOUNTING)) {
- if (!empty($conf->accounting->enabled)) {
- // Accountancy_code_sell
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
- print '<td>';
- if ($type == 0) {
- $accountancy_code_sell = (GETPOSTISSET('accountancy_code_sell') ? GETPOST('accountancy_code_sell', 'alpha') : $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT);
- } else {
- $accountancy_code_sell = (GETPOSTISSET('accountancy_code_sell') ? GETPOST('accountancy_code_sell', 'alpha') : $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT);
- }
- print $formaccounting->select_account($accountancy_code_sell, 'accountancy_code_sell', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
- print '</td></tr>';
- // Accountancy_code_sell_intra
- if ($mysoc->isInEEC()) {
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
- print '<td>';
- if ($type == 0) {
- $accountancy_code_sell_intra = (GETPOSTISSET('accountancy_code_sell_intra') ? GETPOST('accountancy_code_sell_intra', 'alpha') : $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT);
- } else {
- $accountancy_code_sell_intra = (GETPOSTISSET('accountancy_code_sell_intra') ? GETPOST('accountancy_code_sell_intra', 'alpha') : $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT);
- }
- print $formaccounting->select_account($accountancy_code_sell_intra, 'accountancy_code_sell_intra', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
- print '</td></tr>';
- }
- // Accountancy_code_sell_export
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
- print '<td>';
- if ($type == 0) {
- $accountancy_code_sell_export = (GETPOST('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export', 'alpha') : $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT);
- } else {
- $accountancy_code_sell_export = (GETPOST('accountancy_code_sell_export') ? GETPOST('accountancy_code_sell_export', 'alpha') : $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT);
- }
- print $formaccounting->select_account($accountancy_code_sell_export, 'accountancy_code_sell_export', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
- print '</td></tr>';
- // Accountancy_code_buy
- print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
- print '<td>';
- if ($type == 0) {
- $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT);
- } else {
- $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT);
- }
- print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
- print '</td></tr>';
- // Accountancy_code_buy_intra
- if ($mysoc->isInEEC()) {
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
- print '<td>';
- if ($type == 0) {
- $accountancy_code_buy_intra = (GETPOSTISSET('accountancy_code_buy_intra') ? GETPOST('accountancy_code_buy_intra', 'alpha') : $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT);
- } else {
- $accountancy_code_buy_intra = (GETPOSTISSET('accountancy_code_buy_intra') ? GETPOST('accountancy_code_buy_intra', 'alpha') : $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT);
- }
- print $formaccounting->select_account($accountancy_code_buy_intra, 'accountancy_code_buy_intra', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
- print '</td></tr>';
- }
- // Accountancy_code_buy_export
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
- print '<td>';
- if ($type == 0) {
- $accountancy_code_buy_export = (GETPOST('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export', 'alpha') : $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT);
- } else {
- $accountancy_code_buy_export = (GETPOST('accountancy_code_buy_export') ? GETPOST('accountancy_code_buy_export', 'alpha') : $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT);
- }
- print $formaccounting->select_account($accountancy_code_buy_export, 'accountancy_code_buy_export', 1, null, 1, 1, 'minwidth150 maxwidth300', 1);
- print '</td></tr>';
- } else {// For external software
- if (!empty($accountancy_code_sell)) {
- $object->accountancy_code_sell = $accountancy_code_sell;
- }
- if (!empty($accountancy_code_sell_intra)) {
- $object->accountancy_code_sell_intra = $accountancy_code_sell_intra;
- }
- if (!empty($accountancy_code_sell_export)) {
- $object->accountancy_code_sell_export = $accountancy_code_sell_export;
- }
- if (!empty($accountancy_code_buy)) {
- $object->accountancy_code_buy = $accountancy_code_buy;
- }
- if (!empty($accountancy_code_buy_intra)) {
- $object->accountancy_code_buy_intra = $accountancy_code_buy_intra;
- }
- if (!empty($accountancy_code_buy_export)) {
- $object->accountancy_code_buy_export = $accountancy_code_buy_export;
- }
- // Accountancy_code_sell
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
- print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
- print '</td></tr>';
- // Accountancy_code_sell_intra
- if ($mysoc->isInEEC()) {
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
- print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_sell_intra" value="'.$object->accountancy_code_sell_intra.'">';
- print '</td></tr>';
- }
- // Accountancy_code_sell_export
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
- print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_sell_export" value="'.$object->accountancy_code_sell_export.'">';
- print '</td></tr>';
- // Accountancy_code_buy
- print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
- print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
- print '</td></tr>';
- // Accountancy_code_buy_intra
- if ($mysoc->isInEEC()) {
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
- print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_buy_intra" value="'.$object->accountancy_code_buy_intra.'">';
- print '</td></tr>';
- }
- // Accountancy_code_buy_export
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
- print '<td class="maxwidthonsmartphone"><input class="minwidth150" name="accountancy_code_buy_export" value="'.$object->accountancy_code_buy_export.'">';
- print '</td></tr>';
- }
- }
- print '</table>';
- print dol_get_fiche_end();
- print $form->buttonsSaveCancel("Create");
- print '</form>';
- } elseif ($object->id > 0) {
- /*
- * Product card
- */
- // Fiche en mode edition
- if ($action == 'edit' && $usercancreate) {
- //WYSIWYG Editor
- require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
- if (!empty($conf->use_javascript_ajax)) {
- print '<script type="text/javascript">';
- print '$(document).ready(function () {
- $("#selectcountry_id").change(function () {
- document.formprod.action.value="edit";
- document.formprod.submit();
- });
- });';
- print '</script>'."\n";
- }
- // We set country_id, country_code and country for the selected country
- $object->country_id = GETPOST('country_id') ? GETPOST('country_id') : $object->country_id;
- if ($object->country_id) {
- $tmparray = getCountry($object->country_id, 'all');
- $object->country_code = $tmparray['code'];
- $object->country = $tmparray['label'];
- }
- $type = $langs->trans('Product');
- if ($object->isService()) {
- $type = $langs->trans('Service');
- }
- //print load_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), "");
- // Main official, simple, and not duplicated code
- print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST" name="formprod">'."\n";
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="update">';
- print '<input type="hidden" name="id" value="'.$object->id.'">';
- print '<input type="hidden" name="canvas" value="'.$object->canvas.'">';
- $head = product_prepare_head($object);
- $titre = $langs->trans("CardProduct".$object->type);
- $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
- print dol_get_fiche_head($head, 'card', $titre, 0, $picto);
- print '<table class="border allwidth">';
- // Ref
- print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td colspan="3"><input name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag($object->ref).'"></td></tr>';
- // Label
- print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td colspan="3"><input name="label" class="minwidth300 maxwidth400onsmartphone" maxlength="255" value="'.dol_escape_htmltag($object->label).'"></td></tr>';
- // Status To sell
- print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td colspan="3">';
- print '<select class="flat" name="statut">';
- if ($object->status) {
- print '<option value="1" selected>'.$langs->trans("OnSell").'</option>';
- print '<option value="0">'.$langs->trans("NotOnSell").'</option>';
- } else {
- print '<option value="1">'.$langs->trans("OnSell").'</option>';
- print '<option value="0" selected>'.$langs->trans("NotOnSell").'</option>';
- }
- print '</select>';
- print '</td></tr>';
- // Status To Buy
- print '<tr><td class="fieldrequired">'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td colspan="3">';
- print '<select class="flat" name="statut_buy">';
- if ($object->status_buy) {
- print '<option value="1" selected>'.$langs->trans("ProductStatusOnBuy").'</option>';
- print '<option value="0">'.$langs->trans("ProductStatusNotOnBuy").'</option>';
- } else {
- print '<option value="1">'.$langs->trans("ProductStatusOnBuy").'</option>';
- print '<option value="0" selected>'.$langs->trans("ProductStatusNotOnBuy").'</option>';
- }
- print '</select>';
- print '</td></tr>';
- // Batch number managment
- if ($conf->productbatch->enabled) {
- if ($object->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
- print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td>';
- $statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"), '2' => $langs->trans("ProductStatusOnSerial"));
- print $form->selectarray('status_batch', $statutarray, $object->status_batch);
- print '</td></tr>';
- if (!empty($object->status_batch) || !empty($conf->use_javascript_ajax)) {
- $langs->load("admin");
- $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
- $tooltip .= '<br>'.$langs->trans("GenericMaskCodes2");
- $tooltip .= '<br>'.$langs->trans("GenericMaskCodes3");
- $tooltip .= '<br>'.$langs->trans("GenericMaskCodes4a", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
- $tooltip .= '<br>'.$langs->trans("GenericMaskCodes5");
- print '<tr><td id="mask_option">'.$langs->trans("ManageLotMask").'</td>';
- if ($object->status_batch == '1' && getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_LOT_ADDON') == 'mod_lot_advanced') {
- $mask = !empty($object->batch_mask) ? $object->batch_mask : getDolGlobalString('LOT_ADVANCED_MASK');
- }
- if ($object->status_batch == '2' && getDolGlobalString('PRODUCTBATCH_SN_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_SN_ADDON') == 'mod_sn_advanced') {
- $mask = !empty($object->batch_mask) ? $object->batch_mask : getDolGlobalString('SN_ADVANCED_MASK');
- }
- $inherited_mask_lot = getDolGlobalString('LOT_ADVANCED_MASK');
- $inherited_mask_sn = getDolGlobalString('SN_ADVANCED_MASK');
- print '<td id="field_mask">';
- print $form->textwithpicto('<input type="text" class="flat minwidth175" name="batch_mask" id="batch_mask_input" value="'.$mask.'">', $tooltip, 1, 1);
- // Add javascript to sho/hide field for custom mask
- if (!empty($conf->use_javascript_ajax)) {
- print '<script type="text/javascript">
- $(document).ready(function() {
- $("#field_mask").parent().addClass("hideobject");
- var preselect = document.getElementById("status_batch");';
- if (getDolGlobalString('PRODUCTBATCH_SN_USE_PRODUCT_MASKS')) {
- print 'if (preselect.value == "2") {
- $("#field_mask").parent().removeClass("hideobject");
- }';
- }
- if (getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS')) {
- print 'if (preselect.value == "1") {
- $("#field_mask").parent().removeClass("hideobject");
- }';
- }
- print '$("#status_batch").on("change", function () {
- var optionSelected = $("option:selected", this);
- var valueSelected = this.value;
- $("#field_mask").parent().addClass("hideobject");
- ';
- if (getDolGlobalString('PRODUCTBATCH_LOT_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_LOT_ADDON') == 'mod_lot_advanced') {
- print '
- if (this.value == 1) {
- $("#field_mask").parent().removeClass("hideobject");
- $("#batch_mask_input").val("'.$inherited_mask_lot.'");
- }
- ';
- }
- if (getDolGlobalString('PRODUCTBATCH_SN_USE_PRODUCT_MASKS') && getDolGlobalString('PRODUCTBATCH_SN_ADDON') == 'mod_sn_advanced') {
- print '
- if (this.value == 2) {
- $("#field_mask").parent().removeClass("hideobject");
- $("#batch_mask_input").val("'.$inherited_mask_sn.'");
- }
- ';
- }
- print '
- })
- })
- </script>';
- }
- print '</td></tr>';
- }
- }
- }
- // Barcode
- $showbarcode = empty($conf->barcode->enabled) ? 0 : 1;
- if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
- $showbarcode = 0;
- }
- if ($showbarcode) {
- print '<tr><td>'.$langs->trans('BarcodeType').'</td><td>';
- if (GETPOSTISSET('fk_barcode_type')) {
- $fk_barcode_type = GETPOST('fk_barcode_type');
- } else {
- $fk_barcode_type = $object->barcode_type;
- if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) {
- $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
- }
- }
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
- $formbarcode = new FormBarCode($db);
- print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
- print '</td></tr>';
- print '<tr><td>'.$langs->trans("BarcodeValue").'</td><td>';
- $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
- if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) {
- $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type);
- }
- print '<input class="maxwidth150 maxwidthonsmartphone" type="text" name="barcode" value="'.dol_escape_htmltag($tmpcode).'">';
- print '</td></tr>';
- }
- // Description (used in invoice, propal...)
- print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
- // We use dolibarr_details as type of DolEditor here, because we must not accept images as description is included into PDF and not accepted by TCPDF.
- $doleditor = new DolEditor('desc', $object->description, '', 160, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_4, '90%');
- $doleditor->Create();
- print "</td></tr>";
- print "\n";
- // Public Url
- if (empty($conf->global->PRODUCT_DISABLE_PUBLIC_URL)) {
- print '<tr><td>'.$langs->trans("PublicUrl").'</td><td>';
- print img_picto('', 'globe', 'class="pictofixedwidth"');
- print '<input type="text" name="url" class="quatrevingtpercent" value="'.$object->url.'">';
- print '</td></tr>';
- }
- // Stock
- if ($object->isProduct() && !empty($conf->stock->enabled)) {
- // Default warehouse
- print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
- print img_picto($langs->trans("DefaultWarehouse"), 'stock', 'class="pictofixedwidth"');
- print $formproduct->selectWarehouses($object->fk_default_warehouse, 'fk_default_warehouse', 'warehouseopen', 1);
- print ' <a href="'.DOL_URL_ROOT.'/product/stock/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF'].'?action=create&type='.GETPOST('type', 'int')).'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddWarehouse").'"></span></a>';
- print '</td></tr>';
- /*
- print "<tr>".'<td>'.$langs->trans("StockLimit").'</td><td>';
- print '<input name="seuil_stock_alerte" size="4" value="'.$object->seuil_stock_alerte.'">';
- print '</td>';
- print '<td>'.$langs->trans("DesiredStock").'</td><td>';
- print '<input name="desiredstock" size="4" value="'.$object->desiredstock.'">';
- print '</td></tr>';
- */
- }
- /*
- else
- {
- print '<input name="seuil_stock_alerte" type="hidden" value="'.$object->seuil_stock_alerte.'">';
- print '<input name="desiredstock" type="hidden" value="'.$object->desiredstock.'">';
- }*/
- if ($object->isService()) {
- // Duration
- print '<tr><td>'.$langs->trans("Duration").'</td><td>';
- print '<input name="duration_value" size="5" value="'.$object->duration_value.'"> ';
- print $formproduct->selectMeasuringUnits("duration_unit", "time", $object->duration_unit, 0, 1);
- // Mandatory period
- print ' ';
- print '<input type="checkbox" id="mandatoryperiod" name="mandatoryperiod"'.($object->mandatory_period == 1 ? ' checked="checked"' : '').'>';
- print '<label for="mandatoryperiod">';
- $htmltooltip = $langs->trans("mandatoryHelper");
- print $form->textwithpicto($langs->trans("mandatoryperiod"), $htmltooltip, 1, 0);
- print '</label>';
- print '</td></tr>';
- } else {
- if (empty($conf->global->PRODUCT_DISABLE_NATURE)) {
- // Nature
- print '<tr><td>'.$form->textwithpicto($langs->trans("NatureOfProductShort"), $langs->trans("NatureOfProductDesc")).'</td><td>';
- print $formproduct->selectProductNature('finished', $object->finished);
- print '</td></tr>';
- }
- }
- if (!$object->isService() && !empty($conf->bom->enabled)) {
- print '<tr><td>'.$form->textwithpicto($langs->trans("DefaultBOM"), $langs->trans("DefaultBOMDesc", $langs->transnoentitiesnoconv("Finished"))).'</td><td>';
- $bomkey = "Bom:bom/class/bom.class.php:0:t.status=1 AND t.fk_product=".((int) $object->id);
- print $form->selectForForms($bomkey, 'fk_default_bom', $object->fk_default_bom, 1);
- print '</td></tr>';
- }
- if (!$object->isService()) {
- if (empty($conf->global->PRODUCT_DISABLE_WEIGHT)) {
- // Brut Weight
- print '<tr><td>'.$langs->trans("Weight").'</td><td>';
- print '<input name="weight" size="5" value="'.$object->weight.'"> ';
- print $formproduct->selectMeasuringUnits("weight_units", "weight", $object->weight_units, 0, 2);
- print '</td></tr>';
- }
- if (empty($conf->global->PRODUCT_DISABLE_SIZE)) {
- // Brut Length
- print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td>';
- print '<input name="size" size="5" value="'.$object->length.'">x';
- print '<input name="sizewidth" size="5" value="'.$object->width.'">x';
- print '<input name="sizeheight" size="5" value="'.$object->height.'"> ';
- print $formproduct->selectMeasuringUnits("size_units", "size", $object->length_units, 0, 2);
- print '</td></tr>';
- }
- if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) {
- // Brut Surface
- print '<tr><td>'.$langs->trans("Surface").'</td><td>';
- print '<input name="surface" size="5" value="'.$object->surface.'"> ';
- print $formproduct->selectMeasuringUnits("surface_units", "surface", $object->surface_units, 0, 2);
- print '</td></tr>';
- }
- if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) {
- // Brut Volume
- print '<tr><td>'.$langs->trans("Volume").'</td><td>';
- print '<input name="volume" size="5" value="'.$object->volume.'"> ';
- print $formproduct->selectMeasuringUnits("volume_units", "volume", $object->volume_units, 0, 2);
- print '</td></tr>';
- }
- if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) {
- // Net Measure
- print '<tr><td>'.$langs->trans("NetMeasure").'</td><td>';
- print '<input name="net_measure" size="5" value="'.$object->net_measure.'"> ';
- print $formproduct->selectMeasuringUnits("net_measure_units", "", $object->net_measure_units, 0, 0);
- print '</td></tr>';
- }
- }
- // Units
- if (!empty($conf->global->PRODUCT_USE_UNITS)) {
- print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td>';
- print '<td>';
- print $form->selectUnits($object->fk_unit, 'units');
- print '</td></tr>';
- }
- // Custom code
- if (!$object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) {
- print '<tr><td class="wordbreak">'.$langs->trans("CustomCode").'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.$object->customcode.'"></td></tr>';
- // Origin country
- print '<tr><td>'.$langs->trans("CountryOrigin").'</td>';
- print '<td>';
- print img_picto('', 'globe-americas', 'class="paddingrightonly"');
- print $form->select_country($object->country_id, 'country_id', '', 0, 'minwidth100 maxwidthonsmartphone');
- if ($user->admin) {
- print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
- }
- print '</td></tr>';
- // State
- if (empty($conf->global->PRODUCT_DISABLE_STATE)) {
- print '<tr>';
- if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) {
- print '<td>'.$form->editfieldkey('RegionStateOrigin', 'state_id', '', $object, 0).'</td><td>';
- } else {
- print '<td>'.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).'</td><td>';
- }
- print img_picto('', 'state', 'class="pictofixedwidth"');
- print $formcompany->select_state($object->state_id, $object->country_code);
- print '</td>';
- print '</tr>';
- }
- }
- // Quality control
- if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
- print '<tr><td>'.$langs->trans("LifeTime").'</td><td><input name="lifetime" class="maxwidth100onsmartphone" value="'.$object->lifetime.'"></td></tr>';
- print '<tr><td>'.$langs->trans("QCFrequency").'</td><td><input name="qc_frequency" class="maxwidth100onsmartphone" value="'.$object->qc_frequency.'"></td></tr>';
- }
- // Other attributes
- $parameters = array('colspan' => ' colspan="2"', 'cols' => 2);
- $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- if (empty($reshook)) {
- print $object->showOptionals($extrafields, 'edit', $parameters);
- }
- // Tags-Categories
- if ($conf->categorie->enabled) {
- print '<tr><td>'.$langs->trans("Categories").'</td><td>';
- $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1);
- $c = new Categorie($db);
- $cats = $c->containing($object->id, Categorie::TYPE_PRODUCT);
- $arrayselected = array();
- if (is_array($cats)) {
- foreach ($cats as $cat) {
- $arrayselected[] = $cat->id;
- }
- }
- print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
- print "</td></tr>";
- }
- // Note private
- if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
- print '<tr><td class="tdtop">'.$langs->trans("NoteNotVisibleOnBill").'</td><td>';
- $doleditor = new DolEditor('note_private', $object->note_private, '', 140, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_4, '90%');
- $doleditor->Create();
- print "</td></tr>";
- }
- print '</table>';
- print '<br>';
- print '<table class="border centpercent">';
- if (empty($conf->global->PRODUCT_DISABLE_ACCOUNTING)) {
- if (!empty($conf->accounting->enabled)) {
- // Accountancy_code_sell
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
- print '<td>';
- print $formaccounting->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1, 'minwidth150 maxwidth300');
- print '</td></tr>';
- // Accountancy_code_sell_intra
- if ($mysoc->isInEEC()) {
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
- print '<td>';
- print $formaccounting->select_account($object->accountancy_code_sell_intra, 'accountancy_code_sell_intra', 1, '', 1, 1, 'minwidth150 maxwidth300');
- print '</td></tr>';
- }
- // Accountancy_code_sell_export
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
- print '<td>';
- print $formaccounting->select_account($object->accountancy_code_sell_export, 'accountancy_code_sell_export', 1, '', 1, 1, 'minwidth150 maxwidth300');
- print '</td></tr>';
- // Accountancy_code_buy
- print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
- print '<td>';
- print $formaccounting->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1, 'minwidth150 maxwidth300');
- print '</td></tr>';
- // Accountancy_code_buy_intra
- if ($mysoc->isInEEC()) {
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
- print '<td>';
- print $formaccounting->select_account($object->accountancy_code_buy_intra, 'accountancy_code_buy_intra', 1, '', 1, 1, 'minwidth150 maxwidth300');
- print '</td></tr>';
- }
- // Accountancy_code_buy_export
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
- print '<td>';
- print $formaccounting->select_account($object->accountancy_code_buy_export, 'accountancy_code_buy_export', 1, '', 1, 1, 'minwidth150 maxwidth300');
- print '</td></tr>';
- } else {
- // For external software
- // Accountancy_code_sell
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
- print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.$object->accountancy_code_sell.'">';
- print '</td></tr>';
- // Accountancy_code_sell_intra
- if ($mysoc->isInEEC()) {
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
- print '<td><input name="accountancy_code_sell_intra" class="maxwidth200" value="'.$object->accountancy_code_sell_intra.'">';
- print '</td></tr>';
- }
- // Accountancy_code_sell_export
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
- print '<td><input name="accountancy_code_sell_export" class="maxwidth200" value="'.$object->accountancy_code_sell_export.'">';
- print '</td></tr>';
- // Accountancy_code_buy
- print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
- print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.$object->accountancy_code_buy.'">';
- print '</td></tr>';
- // Accountancy_code_buy_intra
- if ($mysoc->isInEEC()) {
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyIntraCode").'</td>';
- print '<td><input name="accountancy_code_buy_intra" class="maxwidth200" value="'.$object->accountancy_code_buy_intra.'">';
- print '</td></tr>';
- }
- // Accountancy_code_buy_export
- print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyExportCode").'</td>';
- print '<td><input name="accountancy_code_buy_export" class="maxwidth200" value="'.$object->accountancy_code_buy_export.'">';
- print '</td></tr>';
- }
- }
- print '</table>';
- print dol_get_fiche_end();
- print $form->buttonsSaveCancel();
- print '</form>';
- } else {
- // Fiche en mode visu
- $showbarcode = empty($conf->barcode->enabled) ? 0 : 1;
- if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
- $showbarcode = 0;
- }
- $head = product_prepare_head($object);
- $titre = $langs->trans("CardProduct".$object->type);
- $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
- print dol_get_fiche_head($head, 'card', $titre, -1, $picto);
- $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1&type='.$object->type.'">'.$langs->trans("BackToList").'</a>';
- $object->next_prev_filter = " fk_product_type = ".$object->type;
- $shownav = 1;
- if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
- $shownav = 0;
- }
- dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
- print '<div class="fichecenter">';
- print '<div class="fichehalfleft">';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border tableforfield centpercent">';
- // Type
- if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) {
- $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
- print '<tr><td class="titlefield">';
- print (empty($conf->global->PRODUCT_DENY_CHANGE_PRODUCT_TYPE)) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat) : $langs->trans('Type');
- print '</td><td>';
- print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat);
- print '</td></tr>';
- }
- if ($showbarcode) {
- // Barcode type
- print '<tr><td class="nowrap">';
- print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
- print $langs->trans("BarcodeType");
- print '</td>';
- if (($action != 'editbarcodetype') && $usercancreate && $createbarcode) {
- print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbarcodetype&id='.$object->id.'&token='.newToken().'">'.img_edit($langs->trans('Edit'), 1).'</a></td>';
- }
- print '</tr></table>';
- print '</td><td>';
- if ($action == 'editbarcodetype' || $action == 'editbarcode') {
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
- $formbarcode = new FormBarCode($db);
- }
- $fk_barcode_type = '';
- if ($action == 'editbarcodetype') {
- print $formbarcode->formBarcodeType($_SERVER['PHP_SELF'].'?id='.$object->id, $object->barcode_type, 'fk_barcode_type');
- $fk_barcode_type = $object->barcode_type;
- } else {
- $object->fetch_barcode();
- $fk_barcode_type = $object->barcode_type;
- print $object->barcode_type_label ? $object->barcode_type_label : ($object->barcode ? '<div class="warning">'.$langs->trans("SetDefaultBarcodeType").'<div>' : '');
- }
- print '</td></tr>'."\n";
- // Barcode value
- print '<tr><td class="nowrap">';
- print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
- print $langs->trans("BarcodeValue");
- print '</td>';
- if (($action != 'editbarcode') && $usercancreate && $createbarcode) {
- print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbarcode&id='.$object->id.'&token='.newToken().'">'.img_edit($langs->trans('Edit'), 1).'</a></td>';
- }
- print '</tr></table>';
- print '</td><td>';
- if ($action == 'editbarcode') {
- $tmpcode = GETPOSTISSET('barcode') ? GETPOST('barcode') : $object->barcode;
- if (empty($tmpcode) && !empty($modBarCodeProduct->code_auto)) {
- $tmpcode = $modBarCodeProduct->getNextValue($object, $fk_barcode_type);
- }
- print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="setbarcode">';
- print '<input type="hidden" name="barcode_type_code" value="'.$object->barcode_type_code.'">';
- print '<input size="40" class="maxwidthonsmartphone" type="text" name="barcode" value="'.$tmpcode.'">';
- print ' <input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Modify").'">';
- print '</form>';
- } else {
- print showValueWithClipboardCPButton($object->barcode);
- }
- print '</td></tr>'."\n";
- }
- // Batch number management (to batch)
- if (!empty($conf->productbatch->enabled)) {
- if ($object->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
- print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td>';
- print $object->getLibStatut(0, 2);
- print '</td></tr>';
- if ((($object->status_batch == '1' && $conf->global->PRODUCTBATCH_LOT_USE_PRODUCT_MASKS && $conf->global->PRODUCTBATCH_LOT_ADDON == 'mod_lot_advanced')
- || ($object->status_batch == '2' && $conf->global->PRODUCTBATCH_SN_ADDON == 'mod_sn_advanced' && $conf->global->PRODUCTBATCH_SN_USE_PRODUCT_MASKS))) {
- print '<tr><td>'.$langs->trans("ManageLotMask").'</td><td>';
- print $object->batch_mask;
- print '</td></tr>';
- }
- }
- }
- // Accountancy sell code
- print '<tr><td class="nowrap">';
- print $langs->trans("ProductAccountancySellCode");
- print '</td><td>';
- if (!empty($conf->accounting->enabled)) {
- if (!empty($object->accountancy_code_sell)) {
- $accountingaccount = new AccountingAccount($db);
- $accountingaccount->fetch('', $object->accountancy_code_sell, 1);
- print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
- }
- } else {
- print $object->accountancy_code_sell;
- }
- print '</td></tr>';
- // Accountancy sell code intra-community
- if ($mysoc->isInEEC()) {
- print '<tr><td class="nowrap">';
- print $langs->trans("ProductAccountancySellIntraCode");
- print '</td><td>';
- if (!empty($conf->accounting->enabled)) {
- if (!empty($object->accountancy_code_sell_intra)) {
- $accountingaccount2 = new AccountingAccount($db);
- $accountingaccount2->fetch('', $object->accountancy_code_sell_intra, 1);
- print $accountingaccount2->getNomUrl(0, 1, 1, '', 1);
- }
- } else {
- print $object->accountancy_code_sell_intra;
- }
- print '</td></tr>';
- }
- // Accountancy sell code export
- print '<tr><td class="nowrap">';
- print $langs->trans("ProductAccountancySellExportCode");
- print '</td><td>';
- if (!empty($conf->accounting->enabled)) {
- if (!empty($object->accountancy_code_sell_export)) {
- $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 '</td></tr>';
- // Accountancy buy code
- print '<tr><td class="nowrap">';
- print $langs->trans("ProductAccountancyBuyCode");
- print '</td><td>';
- if (!empty($conf->accounting->enabled)) {
- if (!empty($object->accountancy_code_buy)) {
- $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 '</td></tr>';
- // Accountancy buy code intra-community
- if ($mysoc->isInEEC()) {
- print '<tr><td class="nowrap">';
- print $langs->trans("ProductAccountancyBuyIntraCode");
- print '</td><td>';
- if (!empty($conf->accounting->enabled)) {
- if (!empty($object->accountancy_code_buy_intra)) {
- $accountingaccount5 = new AccountingAccount($db);
- $accountingaccount5->fetch('', $object->accountancy_code_buy_intra, 1);
- print $accountingaccount5->getNomUrl(0, 1, 1, '', 1);
- }
- } else {
- print $object->accountancy_code_buy_intra;
- }
- print '</td></tr>';
- }
- // Accountancy buy code export
- print '<tr><td class="nowrap">';
- print $langs->trans("ProductAccountancyBuyExportCode");
- print '</td><td>';
- if (!empty($conf->accounting->enabled)) {
- if (!empty($object->accountancy_code_buy_export)) {
- $accountingaccount6 = new AccountingAccount($db);
- $accountingaccount6->fetch('', $object->accountancy_code_buy_export, 1);
- print $accountingaccount6->getNomUrl(0, 1, 1, '', 1);
- }
- } else {
- print $object->accountancy_code_buy_export;
- }
- print '</td></tr>';
- // Description
- print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>'.(dol_textishtml($object->description) ? $object->description : dol_nl2br($object->description, 1, true)).'</td></tr>';
- // Public URL
- if (empty($conf->global->PRODUCT_DISABLE_PUBLIC_URL)) {
- print '<tr><td>'.$langs->trans("PublicUrl").'</td><td>';
- print dol_print_url($object->url, '_blank', 128);
- print '</td></tr>';
- }
- // Default warehouse
- if ($object->isProduct() && !empty($conf->stock->enabled)) {
- $warehouse = new Entrepot($db);
- $warehouse->fetch($object->fk_default_warehouse);
- print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
- print (!empty($warehouse->id) ? $warehouse->getNomUrl(1) : '');
- print '</td>';
- }
- // Parent product.
- if (!empty($conf->variants->enabled) && ($object->isProduct() || $object->isService())) {
- $combination = new ProductCombination($db);
- if ($combination->fetchByFkProductChild($object->id) > 0) {
- $prodstatic = new Product($db);
- $prodstatic->fetch($combination->fk_product_parent);
- // Parent product
- print '<tr><td>'.$langs->trans("ParentProduct").'</td><td>';
- print $prodstatic->getNomUrl(1);
- print '</td></tr>';
- }
- }
- print '</table>';
- print '</div>';
- print '<div class="fichehalfright"><div class="ficheaddleft">';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border tableforfield centpercent">';
- if ($object->isService()) {
- // Duration
- print '<tr><td class="titlefield">'.$langs->trans("Duration").'</td><td>';
- print $object->duration_value;
- if ($object->duration_value > 1) {
- $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
- } elseif ($object->duration_value > 0) {
- $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
- }
- print (!empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? " ".$langs->trans($dur[$object->duration_unit])." " : '');
- // Mandatory period
- if ($object->duration_value > 0) {
- print ' ';
- }
- $htmltooltip = $langs->trans("mandatoryHelper");
- print '<input type="checkbox" class="" name="mandatoryperiod"'.($object->mandatory_period == 1 ? ' checked="checked"' : '').' disabled>';
- print $form->textwithpicto($langs->trans("mandatoryperiod"), $htmltooltip, 1, 0);
- print '</td></tr>';
- } else {
- if (empty($conf->global->PRODUCT_DISABLE_NATURE)) {
- // Nature
- print '<tr><td class="titlefield">'.$form->textwithpicto($langs->trans("NatureOfProductShort"), $langs->trans("NatureOfProductDesc")).'</td><td>';
- print $object->getLibFinished();
- print '</td></tr>';
- }
- }
- if (!$object->isService() && !empty($conf->bom->enabled) && $object->finished) {
- print '<tr><td class="titlefield">'.$form->textwithpicto($langs->trans("DefaultBOM"), $langs->trans("DefaultBOMDesc", $langs->transnoentitiesnoconv("Finished"))).'</td><td>';
- if ($object->fk_default_bom) {
- $bom_static = new BOM($db);
- $bom_static->fetch($object->fk_default_bom);
- print $bom_static->getNomUrl(1);
- }
- print '</td></tr>';
- }
- if (!$object->isService()) {
- // Brut Weight
- if (empty($conf->global->PRODUCT_DISABLE_WEIGHT)) {
- print '<tr><td class="titlefield">'.$langs->trans("Weight").'</td><td>';
- if ($object->weight != '') {
- print $object->weight." ".measuringUnitString(0, "weight", $object->weight_units);
- } else {
- print ' ';
- }
- print "</td></tr>\n";
- }
- if (empty($conf->global->PRODUCT_DISABLE_SIZE)) {
- // Brut Length
- print '<tr><td>'.$langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").'</td><td>';
- if ($object->length != '' || $object->width != '' || $object->height != '') {
- print $object->length;
- if ($object->width) {
- print " x ".$object->width;
- }
- if ($object->height) {
- print " x ".$object->height;
- }
- print ' '.measuringUnitString(0, "size", $object->length_units);
- } else {
- print ' ';
- }
- print "</td></tr>\n";
- }
- if (empty($conf->global->PRODUCT_DISABLE_SURFACE)) {
- // Brut Surface
- print '<tr><td>'.$langs->trans("Surface").'</td><td>';
- if ($object->surface != '') {
- print $object->surface." ".measuringUnitString(0, "surface", $object->surface_units);
- } else {
- print ' ';
- }
- print "</td></tr>\n";
- }
- if (empty($conf->global->PRODUCT_DISABLE_VOLUME)) {
- // Brut Volume
- print '<tr><td>'.$langs->trans("Volume").'</td><td>';
- if ($object->volume != '') {
- print $object->volume." ".measuringUnitString(0, "volume", $object->volume_units);
- } else {
- print ' ';
- }
- print "</td></tr>\n";
- }
- if (!empty($conf->global->PRODUCT_ADD_NET_MEASURE)) {
- // Net Measure
- print '<tr><td class="titlefield">'.$langs->trans("NetMeasure").'</td><td>';
- if ($object->net_measure != '') {
- print $object->net_measure." ".measuringUnitString($object->net_measure_units);
- } else {
- print ' ';
- }
- print '</td></tr>';
- }
- }
- // Unit
- if (!empty($conf->global->PRODUCT_USE_UNITS)) {
- $unit = $object->getLabelOfUnit();
- print '<tr><td>'.$langs->trans('DefaultUnitToShow').'</td><td>';
- if ($unit !== '') {
- print $langs->trans($unit);
- }
- print '</td></tr>';
- }
- // Custom code
- if (!$object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) {
- print '<tr><td>'.$langs->trans("CustomCode").'</td><td>'.$object->customcode.'</td>';
- // Origin country code
- print '<tr><td>'.$langs->trans("Origin").'</td><td>'.getCountry($object->country_id, 0, $db);
- if (!empty($object->state_id)) {
- print ' - '.getState($object->state_id, 0, $db);
- }
- print '</td>';
- }
- // Quality Control
- if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
- print '<tr><td>'.$langs->trans("LifeTime").'</td><td">'.$object->lifetime.'</td></tr>';
- print '<tr><td>'.$langs->trans("QCFrequency").'</td><td>'.$object->qc_frequency.'</td></tr>';
- }
- // Other attributes
- $parameters = array();
- include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
- // Categories
- if ($conf->categorie->enabled) {
- print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
- print $form->showCategories($object->id, Categorie::TYPE_PRODUCT, 1);
- print "</td></tr>";
- }
- // Note private
- if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
- print '<!-- show Note --> '."\n";
- print '<tr><td class="tdtop">'.$langs->trans("NotePrivate").'</td><td>'.(dol_textishtml($object->note_private) ? $object->note_private : dol_nl2br($object->note_private, 1, true)).'</td></tr>'."\n";
- print '<!-- End show Note --> '."\n";
- }
- print "</table>\n";
- print '</div>';
- print '</div></div>';
- print '<div style="clear:both"></div>';
- print dol_get_fiche_end();
- }
- } elseif ($action != 'create') {
- exit;
- }
- }
- $tmpcode = '';
- if (!empty($modCodeProduct->code_auto)) {
- $tmpcode = $modCodeProduct->getNextValue($object, $object->type);
- }
- $formconfirm = '';
- // Confirm delete product
- if (($action == 'delete' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
- || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js
- $formconfirm = $form->formconfirm("card.php?id=".$object->id, $langs->trans("DeleteProduct"), $langs->trans("ConfirmDeleteProduct"), "confirm_delete", '', 0, "action-delete");
- }
- // Clone confirmation
- if (($action == 'clone' && (empty($conf->use_javascript_ajax) || !empty($conf->dol_use_jmobile))) // Output when action = clone if jmobile or no js
- || (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile))) { // Always output when not jmobile nor js
- // Define confirmation messages
- $formquestionclone = array(
- 'text' => $langs->trans("ConfirmClone"),
- array('type' => 'text', 'name' => 'clone_ref', 'label' => $langs->trans("NewRefForClone"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf").' '.$object->ref : $tmpcode, 'morecss'=>'width150'),
- array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContentProduct"), 'value' => 1),
- array('type' => 'checkbox', 'name' => 'clone_categories', 'label' => $langs->trans("CloneCategoriesProduct"), 'value' => 1),
- );
- if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
- $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("CustomerPrices").')', 'value' => 0);
- }
- if (!empty($conf->global->PRODUIT_SOUSPRODUITS)) {
- $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_composition', 'label' => $langs->trans('CloneCompositionProduct'), 'value' => 1);
- }
- $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneProduct', $object->ref), 'confirm_clone', $formquestionclone, 'yes', 'action-clone', 350, 600);
- }
- // Call Hook formConfirm
- $parameters = array('formConfirm' => $formconfirm, 'object' => $object);
- $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- if (empty($reshook)) {
- $formconfirm .= $hookmanager->resPrint;
- } elseif ($reshook > 0) {
- $formconfirm = $hookmanager->resPrint;
- }
- // Print form confirm
- print $formconfirm;
- /*
- * Action bar
- */
- if ($action != 'create' && $action != 'edit') {
- print "\n".'<div class="tabsAction">'."\n";
- $parameters = array();
- $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- if (empty($reshook)) {
- if ($usercancreate) {
- if (!isset($object->no_button_edit) || $object->no_button_edit <> 1) {
- print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Modify").'</a>';
- }
- if (!isset($object->no_button_copy) || $object->no_button_copy <> 1) {
- if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) {
- print '<span id="action-clone" class="butAction">'.$langs->trans('ToClone').'</span>'."\n";
- } else {
- print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=clone&token='.newToken().'&id='.$object->id.'">'.$langs->trans("ToClone").'</a>';
- }
- }
- }
- $object_is_used = $object->isObjectUsed($object->id);
- if ($usercandelete) {
- if (empty($object_is_used) && (!isset($object->no_button_delete) || $object->no_button_delete <> 1)) {
- if (!empty($conf->use_javascript_ajax) && empty($conf->dol_use_jmobile)) {
- print '<span id="action-delete" class="butActionDelete">'.$langs->trans('Delete').'</span>'."\n";
- } else {
- print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Delete").'</a>';
- }
- } else {
- print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ProductIsUsed").'">'.$langs->trans("Delete").'</a>';
- }
- } else {
- print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("Delete").'</a>';
- }
- }
- print "\n</div>\n";
- }
- /*
- * All the "Add to" areas if PRODUCT_ADD_FORM_ADD_TO is set
- */
- if (!empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action == '' || $action == 'view') && $object->status) {
- //Variable used to check if any text is going to be printed
- $html = '';
- //print '<div class="fichecenter"><div class="fichehalfleft">';
- // Propals
- if (!empty($conf->propal->enabled) && $user->rights->propale->creer) {
- $propal = new Propal($db);
- $langs->load("propal");
- $otherprop = $propal->liste_array(2, 1, 0);
- if (is_array($otherprop) && count($otherprop)) {
- $html .= '<tr><td style="width: 200px;">';
- $html .= $langs->trans("AddToDraftProposals").'</td><td>';
- $html .= $form->selectarray("propalid", $otherprop, 0, 1);
- $html .= '</td></tr>';
- } else {
- $html .= '<tr><td style="width: 200px;">';
- $html .= $langs->trans("AddToDraftProposals").'</td><td>';
- $html .= $langs->trans("NoDraftProposals");
- $html .= '</td></tr>';
- }
- }
- // Commande
- if (!empty($conf->commande->enabled) && $user->rights->commande->creer) {
- $commande = new Commande($db);
- $langs->load("orders");
- $othercom = $commande->liste_array(2, 1, null);
- if (is_array($othercom) && count($othercom)) {
- $html .= '<tr><td style="width: 200px;">';
- $html .= $langs->trans("AddToDraftOrders").'</td><td>';
- $html .= $form->selectarray("commandeid", $othercom, 0, 1);
- $html .= '</td></tr>';
- } else {
- $html .= '<tr><td style="width: 200px;">';
- $html .= $langs->trans("AddToDraftOrders").'</td><td>';
- $html .= $langs->trans("NoDraftOrders");
- $html .= '</td></tr>';
- }
- }
- // Factures
- if (!empty($conf->facture->enabled) && $user->rights->facture->creer) {
- $invoice = new Facture($db);
- $langs->load("bills");
- $otherinvoice = $invoice->liste_array(2, 1, null);
- if (is_array($otherinvoice) && count($otherinvoice)) {
- $html .= '<tr><td style="width: 200px;">';
- $html .= $langs->trans("AddToDraftInvoices").'</td><td>';
- $html .= $form->selectarray("factureid", $otherinvoice, 0, 1);
- $html .= '</td></tr>';
- } else {
- $html .= '<tr><td style="width: 200px;">';
- $html .= $langs->trans("AddToDraftInvoices").'</td><td>';
- $html .= $langs->trans("NoDraftInvoices");
- $html .= '</td></tr>';
- }
- }
- //If any text is going to be printed, then we show the table
- if (!empty($html)) {
- print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
- print '<input type="hidden" name="token" value="'.newToken().'">';
- print '<input type="hidden" name="action" value="addin">';
- print load_fiche_titre($langs->trans("AddToDraft"), '', '');
- print dol_get_fiche_head('');
- $html .= '<tr><td class="nowrap">'.$langs->trans("Quantity").' ';
- $html .= '<input type="text" class="flat" name="qty" size="1" value="1"></td>';
- $html .= '<td class="nowrap">'.$langs->trans("ReductionShort").'(%) ';
- $html .= '<input type="text" class="flat" name="remise_percent" size="1" value="0">';
- $html .= '</td></tr>';
- print '<table width="100%" class="border">';
- print $html;
- print '</table>';
- print '<div class="center">';
- print '<input type="submit" class="button button-add" value="'.$langs->trans("Add").'">';
- print '</div>';
- print dol_get_fiche_end();
- print '</form>';
- }
- }
- /*
- * Generated documents
- */
- if ($action != 'create' && $action != 'edit' && $action != 'delete') {
- print '<div class="fichecenter"><div class="fichehalfleft">';
- print '<a name="builddoc"></a>'; // ancre
- // Documents
- $objectref = dol_sanitizeFileName($object->ref);
- $relativepath = $comref.'/'.$objectref.'.pdf';
- if (!empty($conf->product->multidir_output[$object->entity])) {
- $filedir = $conf->product->multidir_output[$object->entity].'/'.$objectref; //Check repertories of current entities
- } else {
- $filedir = $conf->product->dir_output.'/'.$objectref;
- }
- $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
- $genallowed = $usercanread;
- $delallowed = $usercancreate;
- print $formfile->showdocuments($modulepart, $object->ref, $filedir, $urlsource, $genallowed, $delallowed, '', 0, 0, 0, 28, 0, '', 0, '', $object->default_lang, '', $object);
- $somethingshown = $formfile->numoffiles;
- print '</div><div class="fichehalfright"><div class="ficheaddleft">';
- $MAXEVENT = 10;
- $morehtmlright = '<a href="'.DOL_URL_ROOT.'/product/agenda.php?id='.$object->id.'">';
- $morehtmlright .= $langs->trans("SeeAll");
- $morehtmlright .= '</a>';
- // List of actions on element
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
- $formactions = new FormActions($db);
- $somethingshown = $formactions->showactions($object, 'product', 0, 1, '', $MAXEVENT, '', $morehtmlright); // Show all action for product
- print '</div></div></div>';
- }
- // End of page
- llxFooter();
- $db->close();
|