// $policy - 0 or 1: writeoff/return for IV, back order/cancel for DN
function write($policy=0) {
begin_transaction(); // prevents partial database changes in case of direct delivery/invoice
+ if ($this->reference != 'auto' && $this->trans_no == 0 && !is_new_reference($this->reference, $this->trans_type))
+ {
+ commit_transaction();
+ return -1;
+ }
if (count($this->src_docs) == 0 && ($this->trans_type == ST_SALESINVOICE || $this->trans_type == ST_CUSTDELIVERY)) {
// this is direct document - first add parent
$ref = $this->reference;
$date = $this->document_date;
+ $due_date = $this->due_date;
$this->trans_type = get_parent_type($this->trans_type);
$this->reference = 'auto';
$this->read($this->trans_type, $trans_no, true);
$this->document_date = $date;
$this->reference = $ref;
+ $this->due_date = $due_date;
}
$this->reference = @html_entity_decode($this->reference, ENT_QUOTES);
$this->Comments = @html_entity_decode($this->Comments, ENT_QUOTES);