diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 8ca2de4a132..1ef500fcf6b 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -9,7 +9,7 @@ * Copyright (C) 2013-2017 Olivier Geffroy * Copyright (C) 2017 Elarifr. Ari Elbaz * Copyright (C) 2017-2019 Frédéric France - + * Copyright (C) 2017 André Schild * * 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 @@ -51,6 +51,7 @@ class AccountancyExport public static $EXPORT_TYPE_AGIRIS = 9; public static $EXPORT_TYPE_FEC = 11; public static $EXPORT_TYPE_OPENCONCERTO = 12; + public static $EXPORT_TYPE_SAGE50_SWISS = 13; /** @@ -106,6 +107,7 @@ class AccountancyExport self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'), self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'), self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'), + self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'), ); } @@ -130,6 +132,7 @@ class AccountancyExport self::$EXPORT_TYPE_AGIRIS => 'agiris', self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto', self::$EXPORT_TYPE_FEC => 'fec', + self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch', ); return $formatcode[$type]; @@ -194,6 +197,10 @@ class AccountancyExport 'label' => $langs->trans('Modelcsv_openconcerto'), 'ACCOUNTING_EXPORT_FORMAT' => 'csv', ), + self::$EXPORT_TYPE_SAGE50_SWISS => array( + 'label' => $langs->trans('Modelcsv_Sage50_Swiss'), + 'ACCOUNTING_EXPORT_FORMAT' => 'csv', + ), ), 'cr'=> array ( '1' => $langs->trans("Unix"), @@ -261,6 +268,9 @@ class AccountancyExport case self::$EXPORT_TYPE_FEC : $this->exportFEC($TData); break; + case self::$EXPORT_TYPE_SAGE50_SWISS : + $this->exportSAGE50SWISS($TData); + break; default: $this->errors[] = $langs->trans('accountancy_error_modelnotfound'); break; @@ -757,6 +767,157 @@ class AccountancyExport } } + /** + * Export format : SAGE50SWISS + * + * + * https://onlinehelp.sageschweiz.ch/default.aspx?tabid=19984 + * http://media.topal.ch/Public/Schnittstellen/TAF/Specification/Sage50-TAF-format.pdf + * + * @param array $objectLines data + * + * @return void + */ + public function exportSAGE50SWISS($objectLines) + { + // SAGE50SWISS + $this->separator = ','; + $this->end_line = "\r\n"; + + // Print header line + print "Blg,Datum,Kto,S/H,Grp,GKto,SId,SIdx,KIdx,BTyp,MTyp,Code,Netto,Steuer,FW-Betrag,Tx1,Tx2,PkKey,OpId,Flag"; + print $this->end_line; + $thisPieceNum= ""; + $thisPieceAccountNr= ""; + $aSize= count($objectLines); + foreach ($objectLines as $aIndex=>$line) + { + $sammelBuchung= false; + if ($aIndex-2 >= 0 && $objectLines[$aIndex-2]->piece_num == $line->piece_num) + { + $sammelBuchung= true; + } + elseif ($aIndex+2 < $aSize && $objectLines[$aIndex+2]->piece_num == $line->piece_num) + { + $sammelBuchung= true; + } + elseif ($aIndex+1 < $aSize + && $objectLines[$aIndex+1]->piece_num == $line->piece_num + && $aIndex-1 < $aSize + && $objectLines[$aIndex-1]->piece_num == $line->piece_num + ) + { + $sammelBuchung= true; + } + + //Blg + print $line->piece_num . $this->separator; + + // Datum + $date = dol_print_date($line->doc_date, '%d.%m.%Y'); + print $date . $this->separator; + + // Kto + print length_accountg($line->numero_compte) . $this->separator; + // S/H + if ($line->sens == 'D') + { + print 'S' . $this->separator; + } + else + { + print 'H' . $this->separator; + } + //Grp + print self::trunc($line->code_journal, 1) . $this->separator; + // GKto + if (empty($line->code_tiers)) + { + if ($line->piece_num == $thisPieceNum) + { + print length_accounta($thisPieceAccountNr) . $this->separator; + } + else + { + print "div" . $this->separator; + } + } + else + { + print length_accounta($line->code_tiers) . $this->separator; + } + //SId + print $this->separator; + //SIdx + print "0" . $this->separator; + //KIdx + print "0" . $this->separator; + //BTyp + print "0" . $this->separator; + + //MTyp 1=Fibu Einzelbuchung 2=Sammebuchung + if ($sammelBuchung) + { + print "2" . $this->separator; + } + else + { + print "1" . $this->separator; + } + // Code + print '""' . $this->separator; + // Netto + if ($line->montant >= 0) + { + print $line->montant . $this->separator; + } + else + { + print $line->montant*-1 . $this->separator; + } + // Steuer + print "0.00" . $this->separator; + // FW-Betrag + print "0.00" . $this->separator; + // Tx1 + $line1= self::toAnsi($line->label_compte, 29); + if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) + { + $line1= ""; + } + $line2= self::toAnsi($line->doc_ref, 29); + if (strlen($line1) == 0) + { + $line1= $line2; + $line2= ""; + } + if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) + { + $line1= $line1 . ' / ' . $line2; + $line2= ""; + } + + print '"' . self::toAnsi($line1). '"' . $this->separator; + // Tx2 + print '"' . self::toAnsi($line2). '"' . $this->separator; + //PkKey + print "0" . $this->separator; + //OpId + print $this->separator; + + // Flag + print "0"; + + print $this->end_line; + + if ($line->piece_num !== $thisPieceNum) + { + $thisPieceNum= $line->piece_num; + $thisPieceAccountNr= $line->numero_compte; + } + } + } + /** * * @param string $str data @@ -767,4 +928,20 @@ class AccountancyExport { return dol_trunc($str, $size, 'right', 'UTF-8', 1); } + + /** + * + * @param unknown $str Original string to encode and optionaly truncate + * @param integer $size trucate string after $size characters + * @return string String encoded in Windows-1251 charset + */ + public static function toAnsi($str, $size = -1) + { + $retVal= dol_string_nohtmltag($str, 1, 'Windows-1251'); + if ($retVal >= 0 && $size >= 0) + { + $retVal= mb_substr($retVal, 0, $size, 'Windows-1251'); + } + return $retVal; + } } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index d2012870a31..6a5f333492e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -4051,6 +4051,33 @@ class OrderLine extends CommonOrderLine $error=0; + // check if order line is not in a shipment line before deleting + $sqlCheckShipmentLine = "SELECT"; + $sqlCheckShipmentLine .= " ed.rowid"; + $sqlCheckShipmentLine .= " FROM " . MAIN_DB_PREFIX . "expeditiondet ed"; + $sqlCheckShipmentLine .= " WHERE ed.fk_origin_line = " . $this->rowid; + + $resqlCheckShipmentLine = $this->db->query($sqlCheckShipmentLine); + if (!$resqlCheckShipmentLine) { + $error++; + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + } else { + $langs->load('errors'); + $num = $this->db->num_rows($resqlCheckShipmentLine); + if ($num > 0) { + $error++; + $objCheckShipmentLine = $this->db->fetch_object($resqlCheckShipmentLine); + $this->error = $langs->trans('ErrorRecordAlreadyExists') . ' : ' . $langs->trans('ShipmentLine') . ' ' . $objCheckShipmentLine->rowid; + $this->errors[] = $this->error; + } + $this->db->free($resqlCheckShipmentLine); + } + if ($error) { + dol_syslog(__METHOD__ . 'Error ; ' . $this->error, LOG_ERR); + return -1; + } + $this->db->begin(); $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid=".$this->rowid; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 25b8f8d11aa..20b9862e187 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -292,6 +292,7 @@ Modelcsv_agiris=Export for Agiris Modelcsv_openconcerto=Export for OpenConcerto (Test) Modelcsv_configurable=Export CSV Configurable Modelcsv_FEC=Export FEC (Art. L47 A) +Modelcsv_Sage50_Swiss=Export for Sage 50 Switzerland ChartofaccountsId=Chart of accounts Id ## Tools - Init accounting account on product / service diff --git a/htdocs/takepos/takepos.php b/htdocs/takepos/takepos.php index dd2d6524f46..c0a37881cf9 100644 --- a/htdocs/takepos/takepos.php +++ b/htdocs/takepos/takepos.php @@ -573,8 +573,12 @@ $( document ).ready(function() { LoadProducts(0); Refresh(); global->TAKEPOS_NUM_TERMINALS!="1" && $_SESSION["takeposterminal"]=="") print "TerminalsDialog();"; + //IF NO TERMINAL SELECTED + if ($_SESSION["takeposterminal"]=="") + { + if ($conf->global->TAKEPOS_NUM_TERMINALS=="1") $_SESSION["takeposterminal"]=1; + else print "TerminalsDialog();"; + } ?> });