diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d83208c5c1b0e96af8fe84fcedcd6d6e3900b114..9a6838d48867eeb8bae15d5f85ccc08fad123bd7 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2629,7 +2629,7 @@ abstract class CommonObject if ($conf->global->MARGIN_TYPE == "1") print '<td align="right" width="80">'.$langs->trans('BuyingPrice').'</td>'; else - print '<td align="right" width="80">'.$langs->trans('BuyingCost').'</td>'; + print '<td align="right" width="80">'.$langs->trans('CostPrice').'</td>'; if (! empty($conf->global->DISPLAY_MARGIN_RATES)) print '<td align="right" width="50">'.$langs->trans('MarginRate').'</td>'; if (! empty($conf->global->DISPLAY_MARK_RATES)) @@ -3029,7 +3029,10 @@ abstract class CommonObject print '<tr class="liste_titre">'; print '<td width="30%">'.$langs->trans('Margins').'</td>'; print '<td width="20%" align="right">'.$langs->trans('SellingPrice').'</td>'; - print '<td width="20%" align="right">'.$langs->trans('BuyingPrice').'</td>'; + if ($conf->global->MARGIN_TYPE == "1") + print '<td width="20%" align="right">'.$langs->trans('BuyingPrice').'</td>'; + else + print '<td width="20%" align="right">'.$langs->trans('CostPrice').'</td>'; print '<td width="20%" align="right">'.$langs->trans('Margin').'</td>'; if (! empty($conf->global->DISPLAY_MARGIN_RATES)) print '<td align="right">'.$langs->trans('MarginRate').'</td>'; diff --git a/htdocs/core/tpl/freeproductline_create.tpl.php b/htdocs/core/tpl/freeproductline_create.tpl.php index 5c4b055ddf0cfb5d81e00fdfb2e3870f12648979..2457e664ac9b79bb838e7c9f62597080ccbb481b 100644 --- a/htdocs/core/tpl/freeproductline_create.tpl.php +++ b/htdocs/core/tpl/freeproductline_create.tpl.php @@ -44,7 +44,14 @@ if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($ob if (! empty($usemargins)) { ?> - <td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td> + <td align="right"> + <?php + if ($conf->global->MARGIN_TYPE == "1") + echo $langs->trans('BuyingPrice'); + else + echo $langs->trans('CostPrice'); + ?> + </td> <?php if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++; if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; diff --git a/htdocs/core/tpl/predefinedproductline_create.tpl.php b/htdocs/core/tpl/predefinedproductline_create.tpl.php index 6bfd94fa8175beccd2259130aafc4092e350bf81..d03750c98f40b580984d0f162519f0c171bd7af3 100644 --- a/htdocs/core/tpl/predefinedproductline_create.tpl.php +++ b/htdocs/core/tpl/predefinedproductline_create.tpl.php @@ -50,8 +50,15 @@ if (! empty($usemargins)) if (! empty($conf->global->DISPLAY_MARGIN_RATES)) $colspan++; if (! empty($conf->global->DISPLAY_MARK_RATES)) $colspan++; ?> - <td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td> - <?php + <td align="right"> + <?php + if ($conf->global->MARGIN_TYPE == "1") + echo $langs->trans('BuyingPrice'); + else + echo $langs->trans('CostPrice'); + ?> + </td> + <?php } ?> <td colspan="<?php echo $colspan; ?>"> </td> diff --git a/htdocs/fourn/ajax/getSupplierPrices.php b/htdocs/fourn/ajax/getSupplierPrices.php index 3dfe6de2d64e11c08e451be34007999a2339dbbe..67ffbad93ce94de6ea3beecdd27c5a686fbd16a8 100644 --- a/htdocs/fourn/ajax/getSupplierPrices.php +++ b/htdocs/fourn/ajax/getSupplierPrices.php @@ -73,12 +73,9 @@ if (! empty($idprod)) $objp = $db->fetch_object($result); $title = $objp->nom.' - '.$objp->ref_fourn.' - '; - $label = ''; if ($objp->quantity == 1) { - $label.= price($objp->fprice).getCurrencySymbol($conf->currency)."/".strtolower($langs->trans("Unit")); - $title.= price($objp->fprice); $title.= getCurrencySymbol($conf->currency)."/"; @@ -100,8 +97,6 @@ if (! empty($idprod)) $title.=" - "; $title.= price($objp->unitprice).getCurrencySymbol($conf->currency)."/".strtolower($langs->trans("Unit")); - $label.= price($objp->unitprice).getCurrencySymbol($conf->currency)."/".strtolower($langs->trans("Unit")); - $price = $objp->unitprice; } if ($objp->unitcharges > 0 && ($conf->global->MARGIN_TYPE == "2")) { @@ -111,6 +106,8 @@ if (! empty($idprod)) } if ($objp->duration) $label .= " - ".$objp->duration; + $label = price($price).getCurrencySymbol($conf->currency)."/".strtolower($langs->trans("Unit")); + $prices[] = array("id" => $objp->idprodfournprice, "price" => price($price,0,'',0), "label" => $label, "title" => $title); $i++; } diff --git a/htdocs/webservices/demo_wsclient_thirdparty.php-NORUN b/htdocs/webservices/demo_wsclient_thirdparty.php-NORUN index 50b1b6fcb0cb89145e94becd3be69094e5ab53b2..44c9ff5886f7fff2bd0c65bb6ba86d9bd67194a2 100755 --- a/htdocs/webservices/demo_wsclient_thirdparty.php-NORUN +++ b/htdocs/webservices/demo_wsclient_thirdparty.php-NORUN @@ -31,11 +31,13 @@ $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; //$WS_DOL_URL = 'http://localhost:8080/'; // If not a page, should end with / $WS_METHOD_GETTHIRDSPARTY = 'getThirdParty'; $WS_METHOD_CREATETHIRDSPARTY = 'createThirdParty'; +$WS_METHOD_UPDATETHIRDSPARTY = 'updateThirdParty'; $ns='http://www.dolibarr.org/ns/'; //Chosse action to do //$action='get'; $action='create'; +//$action='update'; // Set the WebService URL @@ -121,6 +123,55 @@ if ($action=='create') } } +// Test URL +if ($action=='update') +{ + $thirdparty=array( + 'id'=>'1', + 'ref'=>'Test WS Create Client', + 'ref_ext'=>'WS0001', + 'fk_user_mod'=>'1', + 'status'=>'1', + 'client'=>'1', + 'supplier'=>'0', + 'address'=>'Adresse customer', + 'zip'=>'75000', + 'town'=>'Paris', + 'country_id'=>'1',//France + 'customer_code'=>'-1',//Generate code regarding module configuration + 'supplier_code'=>'0', + 'phone'=>'0141414141', + 'fax'=>'0121212121', + 'email'=>'webtest1@test.fr', + 'url'=>' www.test.fr', + 'profid1'=>'1111111', + 'profid2'=>'222222', + 'profid3'=>'333333', + 'profid4'=>'44444', + 'profid5'=>'55555', + 'profid6'=>'66666', + 'capital'=>'3000', + 'vat_used'=>'0', + 'vat_number'=>'' + //,'options_attr1'=>'Attr1 balbal', //Extra field exemple where field code is attr1 + //'options_attr2'=>'Attr2 balbal' //Extra field exemple where field code is attr2 + ); + + + $parameters = array('authentication'=>$authentication,'thirdparty'=>$thirdparty); + dol_syslog("Call method ".$WS_METHOD_UPDATETHIRDSPARTY); + $result = $soapclient->call($WS_METHOD_UPDATETHIRDSPARTY,$parameters,$ns,''); + if (! $result) + { + print $soapclient->error_str; + print "<br>\n\n"; + print $soapclient->request; + print "<br>\n\n"; + print $soapclient->response; + exit; + } +} + /* * View diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index ee76f7ac8c2b9f3ccc038aa5bd1cd7ce3cc8cd8a..40c5bdefd6ee07edd03c4d0306826f67768578f5 100755 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -219,7 +219,7 @@ $server->register( // Entry values array('authentication'=>'tns:authentication','thirdparty'=>'tns:thirdparty'), // Exit values - array('result'=>'tns:result','id'=>'xsd:string'), + array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string'), $ns, $ns.'#createThirdParty', $styledoc, @@ -227,6 +227,20 @@ $server->register( 'WS to create a thirdparty' ); +// Register WSDL +$server->register( + 'updateThirdParty', + // Entry values + array('authentication'=>'tns:authentication','thirdparty'=>'tns:thirdparty'), + // Exit values + array('result'=>'tns:result'), + $ns, + $ns.'#updateThirdParty', + $styledoc, + $styleuse, + 'WS to update a thirdparty' +); + // Register WSDL $server->register( @@ -465,6 +479,131 @@ function createThirdParty($authentication,$thirdparty) return $objectresp; } +/** + * Update a thirdparty + * + * @param array $authentication Array of authentication information + * @param Societe $thirdparty Thirdparty + * @return array Array result + */ +function updateThirdParty($authentication,$thirdparty) +{ + global $db,$conf,$langs; + + $now=dol_now(); + + dol_syslog("Function: updateThirdParty login=".$authentication['login']); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + // Init and check authentication + $objectresp=array(); + $errorcode='';$errorlabel=''; + $error=0; + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + // Check parameters + if (empty($thirdparty['id'])) { + $error++; $errorcode='KO'; $errorlabel="Thirdparty id is mandatory."; + } + + + if (! $error) + { + $objectfound=false; + + include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + + $object=new Societe($db); + $result=$object->fetch($id); + + if (!empty($thirdparty['id'])) { + + $objectfound=true; + + $object->ref=$thirdparty['ref']; + $object->name=$thirdparty['ref']; + $object->ref_ext=$thirdparty['ref_ext']; + $object->status=$thirdparty['status']; + $object->client=$thirdparty['client']; + $object->fournisseur=$thirdparty['supplier']; + $object->code_client=$thirdparty['customer_code']; + $object->code_fournisseur=$thirdparty['supplier_code']; + $object->code_compta=$thirdparty['customer_code_accountancy']; + $object->code_compta_fournisseur=$thirdparty['supplier_code_accountancy']; + $object->date_creation=$now; + $object->note=$thirdparty['note']; + $object->address=$thirdparty['address']; + $object->zip=$thirdparty['zip']; + $object->town=$thirdparty['town']; + + $object->country_id=$thirdparty['country_id']; + if ($thirdparty['country_code']) $object->country_id=getCountry($thirdparty['country_code'],3); + $object->province_id=$thirdparty['province_id']; + //if ($thirdparty['province_code']) $newobject->province_code=getCountry($thirdparty['province_code'],3); + + $object->phone=$thirdparty['phone']; + $object->fax=$thirdparty['fax']; + $object->email=$thirdparty['email']; + $object->url=$thirdparty['url']; + $object->idprof1=$thirdparty['profid1']; + $object->idprof2=$thirdparty['profid2']; + $object->idprof3=$thirdparty['profid3']; + $object->idprof4=$thirdparty['profid4']; + $object->idprof5=$thirdparty['profid5']; + $object->idprof6=$thirdparty['profid6']; + + $object->capital=$thirdparty['capital']; + + $object->barcode=$thirdparty['barcode']; + $object->tva_assuj=$thirdparty['vat_used']; + $object->tva_intra=$thirdparty['vat_number']; + + $object->canvas=$thirdparty['canvas']; + + //Retreive all extrafield for thirdsparty + // fetch optionals attributes and labels + $extrafields=new ExtraFields($db); + $extralabels=$extrafields->fetch_name_optionals_label('company'); + foreach($extrafields->attribute_label as $key=>$label) + { + $key='options_'.$key; + $object->array_options[$key]=$thirdparty[$key]; + } + + $db->begin(); + + $result=$object->update($fuser); + if ($result <= 0) { + $error++; + } + } + + if ((! $error) && ($objectfound)) + { + $db->commit(); + $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>'')); + } + elseif ($objectfound) + { + $db->rollback(); + $error++; + $errorcode='KO'; + $errorlabel=$object->error; + } else { + $error++; + $errorcode='NOT_FOUND'; + $errorlabel='Thirdparty id='.$thirdparty['id'].' cannot be found'; + } + } + + if ($error) + { + $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); + } + + return $objectresp; +} + /** diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index f87a0af3db97b83cd2669167c3fa9418f8efbcab..e6ed5ebdddb848993bf86179d7d48652b87b761a 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -1,5 +1,6 @@ <?php /* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2013 Marcos GarcĂa <marcosgdf@gmail.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 @@ -169,7 +170,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase * @depends testAdherentFetch * The depends says test is run only if previous is ok */ - public function testAdherentUpdate($localobject) + public function testAdherentUpdate(Adherent $localobject) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -177,6 +178,9 @@ class AdherentTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; + $timestamp = dol_now(); + + $localobject->civilite_id = 0; $localobject->login='newlogin'; $localobject->societe='New company'; $localobject->note='New note after update'; @@ -188,10 +192,12 @@ class AdherentTest extends PHPUnit_Framework_TestCase $localobject->town='New town'; $localobject->country_id=2; $localobject->statut=0; + $localobject->morphy=0; $localobject->phone='New tel pro'; $localobject->phone_perso='New tel perso'; $localobject->phone_mobile='New tel mobile'; $localobject->email='newemail@newemail.com'; + $localobject->naiss=$timestamp; $result=$localobject->update($user); print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0); @@ -207,6 +213,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase print __METHOD__." id=".$localobject->id." result=".$result."\n"; $this->assertLessThan($result, 0); + $this->assertEquals($localobject->civilite_id, $newobject->civilite_id); $this->assertEquals($localobject->login, $newobject->login); $this->assertEquals($localobject->societe, $newobject->societe); $this->assertEquals($localobject->note, $newobject->note); @@ -223,20 +230,54 @@ class AdherentTest extends PHPUnit_Framework_TestCase $this->assertEquals($localobject->phone_perso, $newobject->phone_perso); $this->assertEquals($localobject->phone_mobile, $newobject->phone_mobile); $this->assertEquals($localobject->email, $newobject->email); + $this->assertEquals($localobject->naiss, $timestamp); + $this->assertEquals($localobject->morphy, $newobject->morphy); return $localobject; } + /** + * testAdherentMakeSubstitution + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentUpdate + * The depends says test is run only if previous is ok + */ + public function testAdherentMakeSubstitution(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $template = '%DOL_MAIN_URL_ROOT%,%ID%,%CIVILITE%,%FIRSTNAME%,%LASTNAME%,%FULLNAME%,%COMPANY%,'. + '%ADDRESS%,%ZIP%,%TOWN%,%COUNTRY%,%EMAIL%,%NAISS%,%PHOTO%,%LOGIN%,%PASSWORD%,%PRENOM%,'. + '%NOM%,%SOCIETE%,%ADRESSE%,%CP%,%VILLE%,%PAYS%'; + + $expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',0,New firstname,New name,New firstname New name,'. + 'New company,New address,New zip,New town,,newemail@newemail.com,'.dol_print_date($localobject->naiss,'day').',,'. + 'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,'; + + $result = $localobject->makeSubstitution($template); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($expected, $result); + + return $localobject; + } + /** * testAdherentValid * * @param Adherent $localobject Member instance * @return Adherent * - * @depends testAdherentUpdate + * @depends testAdherentMakeSubstitution * The depends says test is run only if previous is ok */ - public function testAdherentValid($localobject) + public function testAdherentValid(Adherent $localobject) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -260,7 +301,7 @@ class AdherentTest extends PHPUnit_Framework_TestCase * @depends testAdherentValid * The depends says test is run only if previous is ok */ - public function testAdherentOther($localobject) + public function testAdherentOther(Adherent $localobject) { global $conf,$user,$langs,$db; $conf=$this->savconf;