Skip to content

Commit

Permalink
FIX API to push an expense report
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Feb 25, 2020
1 parent 5516c8c commit 91f7a14
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 17 deletions.
33 changes: 32 additions & 1 deletion htdocs/expensereport/class/api_expensereports.class.php
Expand Up @@ -33,7 +33,7 @@ class ExpenseReports extends DolibarrApi
* @var array $FIELDS Mandatory fields, checked when create and update object
*/
static $FIELDS = array(
'socid'
'fk_user_author'
);

/**
Expand Down Expand Up @@ -501,6 +501,11 @@ protected function _cleanObjectDatas($object)
// phpcs:enable
$object = parent::_cleanObjectDatas($object);

unset($object->fk_statut);
unset($object->statut);
unset($object->user);
unset($object->thirdparty);

unset($object->cond_reglement);
unset($object->shipping_method_id);

Expand All @@ -509,6 +514,32 @@ protected function _cleanObjectDatas($object)
unset($object->barcode_type_label);
unset($object->barcode_type_coder);

unset($object->code_paiement);
unset($object->code_statut);
unset($object->fk_c_paiement);
unset($object->fk_incoterms);
unset($object->label_incoterms);
unset($object->location_incoterms);
unset($object->mode_reglement_id);
unset($object->cond_reglement_id);

unset($object->name);
unset($object->lastname);
unset($object->firstname);
unset($object->civility_id);
unset($object->cond_reglement_id);
unset($object->contact);
unset($object->contact_id);

unset($object->state);
unset($object->state_id);
unset($object->state_code);
unset($object->country);
unset($object->country_id);
unset($object->country_code);

unset($object->note); // We already use note_public and note_pricate

return $object;
}

Expand Down
51 changes: 35 additions & 16 deletions htdocs/expensereport/class/expensereport.class.php
Expand Up @@ -58,19 +58,20 @@ class ExpenseReport extends CommonObject

public $date_fin;

/**
* 0=draft, 2=validated (attente approb), 4=canceled, 5=approved, 6=payed, 99=denied
*
* @var int Status
*/
public $status;
public $fk_statut; // -- 0=draft, 2=validated (attente approb), 4=canceled, 5=approved, 6=payed, 99=denied
public $fk_statut;

public $fk_c_paiement;
public $paid;

public $user_author_infos;
public $user_validator_infos;

public $fk_typepayment;
public $num_payment;
public $code_paiement;
public $code_statut;

// ACTIONS

// Create
Expand Down Expand Up @@ -285,10 +286,33 @@ public function create($user, $notrigger = 0)
{
if (is_array($this->lines) && count($this->lines) > 0)
{
foreach ($this->lines as $i => $val)
foreach ($this->lines as $line)
{
// Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
//if (! is_object($line)) $line=json_decode(json_encode($line), false); // convert recursively array into object.
if (!is_object($line)) {
$line = (object) $line;
$newndfline = new ExpenseReportLine($this->db);
$newndfline->fk_expensereport = $line->fk_expensereport;
$newndfline->fk_c_type_fees = $line->fk_c_type_fees;
$newndfline->fk_project = $line->fk_project;
$newndfline->vatrate = $line->vatrate;
$newndfline->vat_src_code = $line->vat_src_code;
$newndfline->comments = $line->comments;
$newndfline->qty = $line->qty;
$newndfline->value_unit = $line->value_unit;
$newndfline->total_ht = $line->total_ht;
$newndfline->total_ttc = $line->total_ttc;
$newndfline->total_tva = $line->total_tva;
$newndfline->date = $line->date;
$newndfline->rule_warning_message = $line->rule_warning_message;
$newndfline->fk_c_exp_tax_cat = $line->fk_c_exp_tax_cat;
$newndfline->fk_ecm_files = $line->fk_ecm_files;
}
else {
$newndfline = $line;
}
//$newndfline=new ExpenseReportLine($this->db);
$newndfline = $this->lines[$i];
$newndfline->fk_expensereport = $this->id;
$result = $newndfline->insert();
if ($result < 0)
Expand Down Expand Up @@ -514,10 +538,8 @@ public function fetch($id, $ref = '')
$sql .= " d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_valid, d.date_approve,"; // DATES (datetime)
$sql .= " d.fk_user_author, d.fk_user_modif, d.fk_user_validator,";
$sql .= " d.fk_user_valid, d.fk_user_approve,";
$sql .= " d.fk_statut as status, d.fk_c_paiement, d.paid,";
$sql .= " dp.libelle as label_payment, dp.code as code_paiement"; // INNER JOIN paiement
$sql .= " d.fk_statut as status, d.fk_c_paiement, d.paid";
$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as dp ON d.fk_c_paiement = dp.id";
if ($ref) $sql .= " WHERE d.ref = '".$this->db->escape($ref)."'";
else $sql .= " WHERE d.rowid = ".$id;
//$sql.= $restrict;
Expand Down Expand Up @@ -566,7 +588,7 @@ public function fetch($id, $ref = '')
elseif ($this->fk_user_validator > 0) $user_approver->fetch($this->fk_user_validator); // For backward compatibility
$this->user_validator_infos = dolGetFirstLastname($user_approver->firstname, $user_approver->lastname);

$this->fk_statut = $obj->status;
$this->fk_statut = $obj->status; // deprecated
$this->status = $obj->status;
$this->fk_c_paiement = $obj->fk_c_paiement;
$this->paid = $obj->paid;
Expand All @@ -578,9 +600,6 @@ public function fetch($id, $ref = '')
$this->user_valid_infos = dolGetFirstLastname($user_valid->firstname, $user_valid->lastname);
}

$this->code_statut = $obj->code_statut;
$this->code_paiement = $obj->code_paiement;

$this->lines = array();

$result = $this->fetch_lines();
Expand Down Expand Up @@ -2650,7 +2669,7 @@ public function insert($notrigger = 0, $fromaddline = false)
$sql .= " ".$this->db->escape($this->total_ht).",";
$sql .= " ".$this->db->escape($this->total_tva).",";
$sql .= " ".$this->db->escape($this->total_ttc).",";
$sql .= "'".$this->db->idate($this->date)."',";
$sql .= " '".$this->db->idate($this->date)."',";
$sql .= " '".$this->db->escape($this->rule_warning_message)."',";
$sql .= " ".$this->db->escape($this->fk_c_exp_tax_cat).",";
$sql .= " ".($this->fk_ecm_files > 0 ? $this->fk_ecm_files : 'null');
Expand Down

0 comments on commit 91f7a14

Please sign in to comment.