Fixed: property must be called billed into web service.

Fixed: web service to create order was useless. it was not possible to
change status.
This commit is contained in:
Laurent Destailleur 2015-01-10 01:07:18 +01:00
parent f7960ec104
commit 87f70f2d22
2 changed files with 265 additions and 65 deletions

View File

@ -61,8 +61,9 @@ class Commande extends CommonOrder
var $contactid;
var $fk_project;
var $statut; // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not)
var $facturee; // deprecated
var $billed; // billed or not
var $facturee; // Facturee ou non
var $brouillon;
var $cond_reglement_id;
var $cond_reglement_code;
@ -435,6 +436,7 @@ class Commande extends CommonOrder
if ($this->statut != 3)
{
dol_syslog(get_class($this)."::set_reopen order has not status closed", LOG_WARNING);
return 0;
}
@ -2482,6 +2484,131 @@ class Commande extends CommonOrder
}
}
/**
* Update database
*
* @param User $user User that modify
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
function update($user=null, $notrigger=0)
{
global $conf, $langs;
$error=0;
// Clean parameters
if (isset($this->ref)) $this->ref=trim($this->ref);
if (isset($this->ref_client)) $this->ref_client=trim($this->ref_client);
if (isset($this->note) || isset($this->note_private)) $this->note_private=(isset($this->note_private) ? trim($this->note_private) : trim($this->note));
if (isset($this->note_public)) $this->note_public=trim($this->note_public);
if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf);
if (isset($this->import_key)) $this->import_key=trim($this->import_key);
// Check parameters
// Put here code to add control on parameters values
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET";
$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
$sql.= " ref_client=".(isset($this->ref_client)?"'".$this->db->escape($this->ref_client)."'":"null").",";
$sql.= " ref_ext=".(isset($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null").",";
$sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").",";
$sql.= " date_commande=".(strval($this->date_commande)!='' ? "'".$this->db->idate($this->date_commande)."'" : 'null').",";
$sql.= " date_valid=".(strval($this->date_validation)!='' ? "'".$this->db->idate($this->date_validation)."'" : 'null').",";
$sql.= " tva=".(isset($this->total_tva)?$this->total_tva:"null").",";
$sql.= " localtax1=".(isset($this->total_localtax1)?$this->total_localtax1:"null").",";
$sql.= " localtax2=".(isset($this->total_localtax2)?$this->total_localtax2:"null").",";
$sql.= " total_ht=".(isset($this->total_ht)?$this->total_ht:"null").",";
$sql.= " total_ttc=".(isset($this->total_ttc)?$this->total_ttc:"null").",";
$sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").",";
$sql.= " fk_user_author=".(isset($this->user_author)?$this->user_author:"null").",";
$sql.= " fk_user_valid=".(isset($this->fk_user_valid)?$this->fk_user_valid:"null").",";
$sql.= " fk_projet=".(isset($this->fk_project)?$this->fk_project:"null").",";
$sql.= " fk_cond_reglement=".(isset($this->cond_reglement_id)?$this->cond_reglement_id:"null").",";
$sql.= " fk_mode_reglement=".(isset($this->mode_reglement_id)?$this->mode_reglement_id:"null").",";
$sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").",";
$sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").",";
$sql.= " model_pdf=".(isset($this->modelpdf)?"'".$this->db->escape($this->modelpdf)."'":"null").",";
$sql.= " import_key=".(isset($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null")."";
$sql.= " WHERE rowid=".$this->id;
$this->db->begin();
dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql) {
$error++; $this->errors[]="Error ".$this->db->lasterror();
}
if (! $error)
{
if (! $notrigger)
{
// Call trigger
$result=$this->call_trigger('ORDER_MODIFY',$user);
if ($result < 0) $error++;
// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return 1;
}
}
/**
* Update value of extrafields on order
*
* @param User $user Object user that modify
* @return int <0 if ko, >0 if ok
*/
function update_extrafields($user)
{
$action='create';
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('orderdao'));
$parameters=array('id'=>$this->id);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$result=$this->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
}
else if ($reshook < 0) $error++;
if (!$error)
{
return 1;
}
else
{
return -1;
}
}
/**
* Delete the customer order
@ -2673,22 +2800,22 @@ class Commande extends CommonOrder
* Return label of status
*
* @param int $statut Id statut
* @param int $facturee if invoiced
* @param int $billed If invoiced
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* @return string Label of status
*/
function LibStatut($statut,$facturee,$mode)
function LibStatut($statut,$billed,$mode)
{
global $langs;
//print 'x'.$statut.'-'.$facturee;
//print 'x'.$statut.'-'.$billed;
if ($mode == 0)
{
if ($statut==-1) return $langs->trans('StatusOrderCanceled');
if ($statut==0) return $langs->trans('StatusOrderDraft');
if ($statut==1) return $langs->trans('StatusOrderValidated');
if ($statut==2) return $langs->trans('StatusOrderSentShort');
if ($statut==3 && (! $facturee && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderToBill');
if ($statut==3 && ($facturee || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderProcessed');
if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderToBill');
if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderProcessed');
}
elseif ($mode == 1)
{
@ -2696,8 +2823,8 @@ class Commande extends CommonOrder
if ($statut==0) return $langs->trans('StatusOrderDraftShort');
if ($statut==1) return $langs->trans('StatusOrderValidatedShort');
if ($statut==2) return $langs->trans('StatusOrderSentShort');
if ($statut==3 && (! $facturee && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderToBillShort');
if ($statut==3 && ($facturee || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderProcessed');
if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderToBillShort');
if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return $langs->trans('StatusOrderProcessed');
}
elseif ($mode == 2)
{
@ -2705,8 +2832,8 @@ class Commande extends CommonOrder
if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0').' '.$langs->trans('StatusOrderDraftShort');
if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1').' '.$langs->trans('StatusOrderValidatedShort');
if ($statut==2) return img_picto($langs->trans('StatusOrderSent'),'statut3').' '.$langs->trans('StatusOrderSentShort');
if ($statut==3 && (! $facturee && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBillShort');
if ($statut==3 && ($facturee || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessedShort');
if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBillShort');
if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessedShort');
}
elseif ($mode == 3)
{
@ -2714,8 +2841,8 @@ class Commande extends CommonOrder
if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0');
if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1');
if ($statut==2) return img_picto($langs->trans('StatusOrderSentShort'),'statut3');
if ($statut==3 && (! $facturee && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7');
if ($statut==3 && ($facturee || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6');
if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7');
if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6');
}
elseif ($mode == 4)
{
@ -2723,8 +2850,8 @@ class Commande extends CommonOrder
if ($statut==0) return img_picto($langs->trans('StatusOrderDraft'),'statut0').' '.$langs->trans('StatusOrderDraft');
if ($statut==1) return img_picto($langs->trans('StatusOrderValidated'),'statut1').' '.$langs->trans('StatusOrderValidated');
if ($statut==2) return img_picto($langs->trans('StatusOrderSentShort'),'statut3').' '.$langs->trans('StatusOrderSent');
if ($statut==3 && (! $facturee && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBill');
if ($statut==3 && ($facturee || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessed');
if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderToBill'),'statut7').' '.$langs->trans('StatusOrderToBill');
if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return img_picto($langs->trans('StatusOrderProcessed'),'statut6').' '.$langs->trans('StatusOrderProcessed');
}
elseif ($mode == 5)
{
@ -2732,8 +2859,8 @@ class Commande extends CommonOrder
if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans('StatusOrderDraftShort').' </span>'.img_picto($langs->trans('StatusOrderDraft'),'statut0');
if ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans('StatusOrderValidatedShort').' </span>'.img_picto($langs->trans('StatusOrderValidated'),'statut1');
if ($statut==2) return '<span class="hideonsmartphone">'.$langs->trans('StatusOrderSentShort').' </span>'.img_picto($langs->trans('StatusOrderSent'),'statut3');
if ($statut==3 && (! $facturee && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return '<span class="hideonsmartphone">'.$langs->trans('StatusOrderToBillShort').' </span>'.img_picto($langs->trans('StatusOrderToBill'),'statut7');
if ($statut==3 && ($facturee || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return '<span class="hideonsmartphone">'.$langs->trans('StatusOrderProcessedShort').' </span>'.img_picto($langs->trans('StatusOrderProcessed'),'statut6');
if ($statut==3 && (! $billed && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return '<span class="hideonsmartphone">'.$langs->trans('StatusOrderToBillShort').' </span>'.img_picto($langs->trans('StatusOrderToBill'),'statut7');
if ($statut==3 && ($billed || ! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) return '<span class="hideonsmartphone">'.$langs->trans('StatusOrderProcessedShort').' </span>'.img_picto($langs->trans('StatusOrderProcessed'),'statut6');
}
}
@ -2954,45 +3081,6 @@ class Commande extends CommonOrder
}
}
/**
* Update value of extrafields on order
*
* @param User $user Object user that modify
* @return int <0 if ko, >0 if ok
*/
function update_extrafields($user)
{
$action='create';
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('orderdao'));
$parameters=array('id'=>$this->id);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$result=$this->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
}
else if ($reshook < 0) $error++;
if (!$error)
{
return 1;
}
else
{
return -1;
}
}
/**
* Return an array of order lines
*
@ -3106,8 +3194,7 @@ class Commande extends CommonOrder
/**
* \class OrderLine
* \brief Classe de gestion des lignes de commande
* Class to mange order lines
*/
class OrderLine extends CommonOrderLine
{

View File

@ -180,7 +180,7 @@ $order_fields = array(
'ref_int' => array('name'=>'ref_int','type'=>'xsd:string'),
'thirdparty_id' => array('name'=>'thirdparty_id','type'=>'xsd:int'),
'status' => array('name'=>'status','type'=>'xsd:int'),
'facturee' => array('name'=>'facturee','type'=>'xsd:string'),
'billed' => array('name'=>'billed','type'=>'xsd:string'),
'total_net' => array('name'=>'total_net','type'=>'xsd:double'),
'total_vat' => array('name'=>'total_vat','type'=>'xsd:double'),
'total_localtax1' => array('name'=>'total_localtax1','type'=>'xsd:double'),
@ -314,8 +314,17 @@ $server->register(
'WS to create an order'
);
$server->register(
'updateOrder',
array('authentication'=>'tns:authentication','order'=>'tns:order'), // Entry values
array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'), // Exit values
$ns,
$ns.'#updateOrder',
$styledoc,
$styleuse,
'WS to update an order'
);
// Register WSDL
$server->register(
'validOrder',
array('authentication'=>'tns:authentication','id'=>'xsd:string'), // Entry values
@ -439,7 +448,7 @@ function getOrder($authentication,$id='',$ref='',$ref_ext='')
'remise_absolue' => $order->remise_absolue,
'source' => $order->source,
'facturee' => $order->facturee,
'billed' => $order->billed,
'note_private' => $order->note_private,
'note_public' => $order->note_public,
'cond_reglement_id' => $order->cond_reglement_id,
@ -596,7 +605,7 @@ function getOrdersForThirdParty($authentication,$idthirdparty)
'remise_absolue' => $order->remise_absolue,
'source' => $order->source,
'facturee' => $order->facturee,
'billed' => $order->billed,
'note_private' => $order->note_private,
'note_public' => $order->note_public,
'cond_reglement_id' => $order->cond_reglement_id,
@ -679,12 +688,12 @@ function createOrder($authentication,$order)
$newobject->note_private=$order['note_private'];
$newobject->note_public=$order['note_public'];
$newobject->statut=0; // We start with status draft
$newobject->facturee=$order['facturee'];
$newobject->billed=$order['billed'];
$newobject->fk_project=$order['project_id'];
$newobject->cond_reglement_id=$order['cond_reglement_id'];
$newobject->demand_reason_id=$order['demand_reason_id'];
$newobject->date_creation=$now;
// Retrieve all extrafield for order
// fetch optionals attributes and labels
$extrafields=new ExtraFields($db);
@ -717,7 +726,7 @@ function createOrder($authentication,$order)
$newline->total_ttc=$line['total'];
$newline->date_start=$line['date_start'];
$newline->date_end=$line['date_end'];
// Retrieve all extrafield for lines
// fetch optionals attributes and labels
$extrafields=new ExtraFields($db);
@ -727,7 +736,7 @@ function createOrder($authentication,$order)
$key='options_'.$key;
$newline->array_options[$key]=$line[$key];
}
$newobject->lines[]=$newline;
}
@ -862,5 +871,109 @@ function validOrder($authentication,$id='')
return $objectresp;
}
/**
* Update an order
*
* @param array $authentication Array of authentication information
* @param array $order Order info
* @return array Array result
*/
function updateOrder($authentication,$order)
{
global $db,$conf,$langs;
$now=dol_now();
dol_syslog("Function: updateOrder 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($order['id']) && empty($order['ref']) && empty($order['ref_ext'])) {
$error++; $errorcode='KO'; $errorlabel="Order id or ref or ref_ext is mandatory.";
}
if (! $error)
{
$objectfound=false;
include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
$object=new Commande($db);
$result=$object->fetch($order['id'],(empty($order['id'])?$order['ref']:''),(empty($order['id']) && empty($order['ref'])?$order['ref_ext']:''));
if (!empty($object->id)) {
$objectfound=true;
$db->begin();
if (isset($order['status']))
{
if ($order['status'] == -1) $result=$object->cancel($fuser);
if ($order['status'] == 1) $result=$object->valid($fuser);
if ($order['status'] == 0) $result=$object->set_reopen($fuser);
if ($order['status'] == 3) $result=$object->cloture($fuser);
}
if (isset($order['billed']))
{
if ($order['billed']) $result=$object->classifyBilled($fuser);
if (! $order['billed']) $result=$object->classifyBilled($fuser);
}
//Retreive all extrafield for object
// fetch optionals attributes and labels
$extrafields=new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label('commande',true);
foreach($extrafields->attribute_label as $key=>$label)
{
$key='options_'.$key;
if (isset($order[$key]))
{
$result=$object->setValueFrom($key, $order[$key], 'commande_extrafields');
}
}
if ($result <= 0) {
$error++;
}
}
if ((! $error) && ($objectfound))
{
$db->commit();
$objectresp=array(
'result'=>array('result_code'=>'OK', 'result_label'=>''),
'id'=>$object->id
);
}
elseif ($objectfound)
{
$db->rollback();
$error++;
$errorcode='KO';
$errorlabel=$object->error;
} else {
$error++;
$errorcode='NOT_FOUND';
$errorlabel='Order id='.$order['id'].' ref='.$order['ref'].' ref_ext='.$order['ref_ext'].' cannot be found';
}
}
if ($error)
{
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
return $objectresp;
}
// Return the results.
$server->service(file_get_contents("php://input"));