noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Acc_Ledger_Sale Class Reference

Handle the ledger of sold,. More...

+ Inheritance diagram for Acc_Ledger_Sale:
+ Collaboration diagram for Acc_Ledger_Sale:

Public Member Functions

 __construct ($p_cn, $p_init)
 construct
 
 confirm ($p_array, $p_summary=false)
 show the summary of the operation and propose to save it
 
 extra_info ()
 the function extra info allows to
 
 get_detail_sale ($p_from, $p_end, $p_filter_operation='all')
 Retrieve data from the view v_detail_sale , gives all the row of an operation.
 
 input ($p_array=null, $p_readonly=0)
 display the form for entering data for invoice,
 
 insert ($p_array=null)
 insert into the database, it calls first the verify function, store the value of the inserted operation in $this->jr_id and this->jr_internal
 
 verify_operation ($p_array)
 verify that the data are correct before inserting or confirming
 
- Public Member Functions inherited from Acc_Ledger
 add_card ($p_filter, $p_id_update)
 Return a button to create new card, depending of the ledger.
 
 button_copy_operation ()
 Show a button to create an operation identical to the recorded one.
 
 button_new_operation ()
 Create a button to encode a new operation into the same ledger.
 
 check_currency ($p_qcode_payment, $p_currency_id)
 When we write a record for the payment at the same time as a sale or a purchase, to have a bank saldo reliable , all the bank operation must be in the same currency Operation = Currency 1 and Bank = Currency 2 then it must failed , except if currency 2 (of the bank is the default currency.
 
 check_currency_setting ($p_currency_code)
 Check that the currency code does exist and the setting of the folder is correct.
 
 check_payment ($e_mp, $e_mp_qcode)
 check if the payment method is valid
 
 check_periode ()
 Check if a Dossier is using the check on the periode, if true than the user has to enter the date and the periode, it is a security check.
 
 check_strict ()
 Check if a Dossier is using the strict mode or not.
 
 compute_internal_code ($p_grpt)
 compute the internal code of the saved operation and set the $this->jr_internal to the computed value
 
 convert_from_follow ($p_ag_id, $copy_description=0)
 convert operations from FOLLOWUP into a SALE , FEENOTE or PURCHASE operation into a suitable array
 
 create_document ($internal, $p_array)
 create the invoice and saved it as attachment to the operation,
 
 CurrencyInput ($p_currency_code, $p_currency_rate, $p_eur_amount)
 Create a select from value for currency and add javascript to update $p_currency_rate and $p_eur_amount.
 
 delete ()
 let you delete a operation
 
 delete_ledger ()
 delete a ledger IF it doesn't contain anything
 
 display_additional_tax ($p_additional_tax, $p_amount)
 in confirm screen , display the compute value for additional tax @parameter $p_additional_tax acc_other_tax.ac_id
 
 display_ledger ()
 display detail of a ledger
 
 display_negative_warning ($p_amount)
 If the amount is positive and the ledger expects a negative amount, il will return the saved warning.
 
 display_warning ($pa_msg, $p_warning)
 Display warning contained in an array.
 
 existing_vat ()
 return the used VAT code with a rate > 0
 
 get_all_fiche_def ()
 retrieve all the card for this type of ledger, make them into a string separated by comma
 
 get_class_def ()
 retrieve the jrn_def_class_deb and return it
 
 get_currency ()
 returns the code iso of the default currency for this ledger
 
 get_customer_late ()
 get info from customer not yet paid
 
 get_customer_now ()
 get info from customer to pay today
 
 get_default_card ($p_ledger_type, $p_side)
 Return an array of default card for the ledger type given.
 
 get_fiche_def ()
 retrieve the jrn_def_fiche and return them into a array index deb, cred
 
 get_first ($p_type, $p_access=3)
 get the first ledger
 
 get_id ($p_internal)
 retrieve the jr_id thanks the internal code, do not change anything to the current object
 
 get_is_loaded ()
 
 get_last ($p_limit)
 return the last p_limit operation into an array
 
 get_last_date ()
 get the date of the last operation
 
 get_last_pj ()
 returns the sequence number of the receipt for the current ledger or create the sequence if it doesn't exist
 
 get_ledger_id ()
 Set the jrn_def.jrn_def_id.
 
 get_min_row ()
 
 get_name ()
 Return the name of a ledger.
 
 get_operation ($p_from, $p_to)
 retrieve operation from jrn
 
 get_operation_date ($p_date, $p_ledger_type, $sql_op)
 Get operation from the ledger type before, after or with the given date .
 
 get_other_amount ($p_jr_id)
 get the amount of vat for a given jr_grpt_id from the table quant_purchase
 
 get_propertie ()
 Get the properties of a journal.
 
 get_rowSimple ($p_from, $p_to, $pa_ledger=[], $trunc=0, $p_limit=-1, $p_offset=-1)
 Get simplified row from ledger Call Acc_Ledger_History_Generic:get_rowSimple.
 
 get_solde ($p_from, $p_to)
 get the saldo of a ledger for a specific period
 
 get_supplier_late ()
 get info from supplier not yet paid
 
 get_supplier_now ()
 get info from supplier to pay today
 
 get_tiers ($p_jrn_type, $jr_id)
 Retrieve the third : supplier for purchase, customer for sale, bank for fin,.
 
 get_tiers_id ($p_jrn_type, $jr_id)
 Return the f_id of the tiers , called by get_tiers.
 
 get_type ()
 Return the type of a ledger (ACH,VEN,ODS or FIN) or GL.
 
 guess_pj ()
 guess what the next pj should be
 
 has_other_tax ()
 returns true if the ledger has an additional tax
 
 has_quantity ()
 Check if a ledger is enabled , 1 for yes and 0 if disabled.
 
 inc_seq_pj ()
 increment the sequence for the pj
 
 input_additional_tax ()
 form : display additional tax available for this ledger and value, set 2 values : checkbox if tax applies and value
 
 input_extra_info ()
 
 input_new ()
 display FORM to enter parameters to create a new ledger.
 
 input_paid ($p_selected, $p_amount=0, $p_date="", $p_comm="")
 Create the section payment.
 
 is_closed ($p_periode)
 check if the current ledger is closed
 
 is_enable ()
 Check if a ledger is enabled , 1 for yes and 0 if disabled.
 
 listing ()
 listing of all ledgers
 
 previous_amount ($p_to)
 retrieve amount of previous periode
 
 previous_other_tax ($p_to)
 retrieve the previous amount
 
 reverse ($p_date, $p_label)
 reverse the operation by creating the opposite one, the result is to avoid it it must be done in
 
 save ($p_array=null)
 save the operation into the jrnx,jrn, , CA and pre_def
 
 save_followup ($s_related_action)
 attach action-followups to an operation,
 
 save_new ($array)
 Insert a new ledger , member variable like jrn_def_id will changed.
 
 search_group ($p_what, $p_value)
 retreive the jr_grpt_id from a ledger
 
 select_default_currency ()
 create a select button to set the default currency for a ledger used only for empty financial ledger
 
 select_depot ($p_readonly, $p_repo)
 Let you select the repository before confirming a sale or a purchase.
 
 select_ledger ($p_type="ALL", $p_access=3, $enable=TRUE)
 Show a select list of the ledgers you can access in writing, reading or simply accessing.
 
 set_currency_id ()
 retrieve currency_id from database
 
 set_is_loaded ($is_loaded)
 
 set_ledger_id ($p_id)
 Set the jrn_def.jrn_def_id.
 
 set_quantity ($p_value)
 set quantity for the ledger to 1 or 0,
 
 update ($array=null)
 update a ledger
 
 update_internal_code ($p_internal)
 
 update_paid ($p_array)
 Update the paiment in the list of operation.
 
 use_quant_table ($p_grpt_id, $p_jrn_type)
 Check if the operation is used in the table quant*.
 
 vat_operation ($p_jr_id)
 get the amount of vat for a given jr_grpt_id from the table quant_purchase
 
 verify_ledger ($array)
 Verify before update.
 

Static Public Member Functions

static heading_detail_sale ()
 compute an array with the heading cells for the details, used for the export in CSV
 
- Static Public Member Functions inherited from Acc_Ledger
static array_cat ()
 create an array of the existing cat, to be used in a checkbox form
 
static next_number ($p_cn, $p_type)
 retrieve the next number for this type of ledger
 
static test_me ($pCase='')
 this function is intended to test this class
 

Additional Inherited Members

- Data Fields inherited from Acc_Ledger
 $currency_id
 !< default number of rows by default 10
 
 $db
 !< jrn_def.jrn_def_id
 
 $id
 
 $ledger_type
 !< row of the ledger
 
 $nb
 !< type of the ledger ACH ODS FIN VEN or GL
 
 $row
 !< database connextion
 
- Protected Member Functions inherited from Acc_Ledger
 find_label ($p_value)
 Retrieve the label of an accounting.
 
 verify_autonumber ($p_array)
 compare given receipt number and suggested one, if different , it means that the user enters a receipt number if e_pj or e_pj_suggest is not set or empty , or if both are equals then will return true, it returns only if they exist and are different
 
 warn_manual_receipt ($p_array)
 warn if the suggested receipt and receipt are different , it means that the user tried to number himself
 
- Protected Attributes inherited from Acc_Ledger
 $is_loaded
 !< is_loaded true the ledger definition is loaded or false, it is not
 

Detailed Description

Handle the ledger of sold,.

Exceptions
throwan exception is something is wrong

Definition at line 36 of file acc_ledger_sale.class.php.

Constructor & Destructor Documentation

◆ __construct()

Acc_Ledger_Sale::__construct ( $p_cn,
$p_id )

construct

Parameters
$p_cndatabase connexion
$p_idjrn.jrn_def_id

Reimplemented from Acc_Ledger.

Definition at line 38 of file acc_ledger_sale.class.php.

38 {
39 parent::__construct($p_cn, $p_init);
40 $this->ledger_type = 'VEN';
41 }

Member Function Documentation

◆ confirm()

Acc_Ledger_Sale::confirm ( $p_array,
$p_summary = false )

show the summary of the operation and propose to save it

Parameters
arraycontains normally $_POST. It proposes also to save the Analytic accountancy
$p_summaryfalse for the feedback, true to show the summary
Returns
string

Reimplemented from Acc_Ledger.

Definition at line 877 of file acc_ledger_sale.class.php.

877 {
878 global $g_parameter,$g_user;
879 extract($p_array, EXTR_SKIP);
880 if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
881 // don't need to verify for a summary
882 if (!$p_summary)
883 {
884 $this->verify($p_array);
885 }
886 $anc = null;
887 // to show a select list for the analytic & VAT USE
888 // if analytic is op (optionnel) there is a blank line
889
890 bcscale(4);
891 $client = new Fiche($this->db);
892 $client->get_by_qcode($e_client, true);
893
894 $client_name = $client->getName() .
895 ' ' . $client->strAttribut(ATTR_DEF_ADRESS) . ' ' .
896 $client->strAttribut(ATTR_DEF_CP) . ' ' .
897 $client->strAttribut(ATTR_DEF_CITY);
898 $lPeriode = new Periode($this->db);
899 if ($this->check_periode() == true) {
900 $lPeriode->p_id = $period;
901 } else {
902 $lPeriode->find_periode($e_date);
903 }
904 $date_limit = $lPeriode->get_date_limit();
905 $r = "";
906 $r .= '<div id="summary_op1" >';
907 $r.='<TABLE>';
908 if ( $p_summary ) {
909 $jr_id=$this->db->get_value('select jr_id from jrn where jr_internal=$1',array($this->internal));
910 $r.="<tr>";
911 $r.='<td>';
912 $r.=_('Détail opération ');
913 $r.='</td>';
914 $r.='<td>';
915 $r.=sprintf ('<a class="line" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a>',
916 $jr_id,dossier::id(),$this->internal);
917 $r.='</td>';
918 $r.="</tr>";
919 }
920 $r.='<tr>';
922 if ( ! $p_summary) {
923 $r.='<td>' . _('Numéro Pièce') .$span.'</td><td>'. hb($e_pj) . '</td>';
924 } else {
925 if ( $g_parameter->MY_PJ_SUGGEST=="A" ||$g_user->check_action(UPDRECEIPT)==0)
926 $e_pj=$this->pj;
927 if ( strcmp($this->pj,$e_pj) != 0 )
928 {
929 $r.='<td>' . _('Numéro Pièce') .$span.'</td><td>'. hb($this->pj) .
930 '<span class="notice"> '._('Attention numéro pièce existante, elle a du être adaptée').'</span></td>';
931 } else {
932 $r.='<td>' . _('Numéro Pièce') .$span.'</td><td>'. hb($this->pj) . '</td>';
933 }
934 }
935 $r.='</tr>';
936 $r.='<tr>';
937 $r.='<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>';
938 $r.='</tr>';
939 $r.='<tr>';
940 $r.='<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>';
941 $r.='</tr>';
942 $r.='<tr>';
943 $r.='<td> ' . _('Période Comptable') . '</td><td> ' .hb( $date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>';
944 $r.='</tr>';
945 $r.='</table>';
946 $r.='</div>';
947 $r .= '<div id="summary_op2">';
948 $r.='<table>';
949 $r.='<tr>';
950 $r.='<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . '</td>';
951 $r.='</tr>';
952 $r.='<tr>';
953 $r.='<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>';
954 $r.='</tr>';
955
956 $r.='<tr>';
957 $r.='<td> ' . _('Client') . '</td><td> ' . hb($e_client . ':' . $client_name) . '</td>';
958 $r.='</tr>';
959 $r.='</table>';
960 $r.='<pre>'._('Note').' '.h($p_array['jrn_note_input']).'</pre>';
961 $r.='</div>';
962 $r.='<div style="float:none;clear:both">';
963 $r.='</div>';
964
965 $r.='<h2 class="h-section" class="h-section">' . _('Détail articles vendus') . '</h2>';
966 $r.='<p class="decale">';
967 $r.='<table class="result" >';
968 $r.='<TR>';
969 $r.="<th>" . _('Code') . "</th>";
970 $r.="<th>" . _('Dénomination') . "</th>";
971 $r.="<th style=\"text-align:right\">" . _('prix') . "</th>";
972 $r.="<th style=\"text-align:right\">" . _('quantité') . "</th>";
973
974
975 if ($g_parameter->MY_TVA_USE == 'Y') {
976 $r.="<th style=\"text-align:right\">" . _('tva') . "</th>";
977 $r.='<th style="text-align:right"> ' . _('Montant TVA') . '</th>';
978 $r.='<th style="text-align:right">' . _('Montant HTVA') . '</th>';
979 $r.='<th style="text-align:right">' . _('Montant TVAC') . '</th>';
980 } else {
981 $r.='<th style="text-align:right">' . _('Montant') . '</th>';
982 }
983 /* if we use the AC */
984 if ($g_parameter->MY_ANALYTIC != 'nu') {
985 $anc = new Anc_Plan($this->db);
986 $a_anc = $anc->get_list();
987 $x = count($a_anc);
988 /* set the width of the col */
989 $r.='<th colspan="' . $x . '">' . _('Compt. Analytique') . '</th>';
990
991 /* add hidden variables pa[] to hold the value of pa_id */
992 $r.=Anc_Plan::hidden($a_anc);
993 }
994 $r.='</tr>';
995 $tot_amount = 0.0;
996 $tot_tva = 0.0;
997 for ($i = 0; $i < $nb_item; $i++) {
998 if (noalyss_strlentrim(${"e_march" . $i}) == 0)
999 continue;
1000
1001 /* retrieve information for card */
1002 $fiche = new Fiche($this->db);
1003 $fiche->get_by_qcode(${"e_march" . $i});
1004 if ($g_parameter->MY_UPDLAB == 'Y')
1005 $fiche_name = h(${"e_march" . $i . "_label"});
1006 else
1007 $fiche_name = $fiche->strAttribut(ATTR_DEF_NAME);
1008 if ($g_parameter->MY_TVA_USE == 'Y') {
1009 $idx_tva = ${"e_march" . $i . "_tva_id"};
1010 $oTva = Acc_Tva::build($this->db,$idx_tva);
1011 $oTva->load();
1012 }
1013 $op = new Acc_Compute();
1014 $amount = bcmul(${"e_march" . $i . "_price"}, ${'e_quant' . $i});
1015 $op->set_parameter("amount", $amount);
1016 if ($g_parameter->MY_TVA_USE == 'Y') {
1017 $op->set_parameter('amount_vat_rate', $oTva->get_parameter('rate'));
1018 $op->compute_vat();
1019 $tva_computed = $op->get_parameter('amount_vat');
1020 $tva_item = ${"e_march" . $i . "_tva_amount"};
1021 if (isset($tva[$idx_tva]))
1022 $tva[$idx_tva]=bcadd($tva[$idx_tva],$tva_item,2);
1023 else
1024 $tva[$idx_tva] = $tva_item;
1025 $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
1026 }
1027 $tot_amount = round(bcadd($tot_amount, $amount), 2);
1028
1029 $r.='<tr>';
1030 $r.='<td>';
1031 $r.=${"e_march" . $i};
1032 $r.='</td>';
1033 $r.='<TD style="border-bottom:1px dotted grey;">';
1034 $r.=$fiche_name;
1035 $r.='</td>';
1036 $r.='<td class="num">';
1037 $r.=nbm(${"e_march" . $i . "_price"},4);
1038 $r.='</td>';
1039 $r.='<td class="num">';
1040 $r.=nbm(${"e_quant" . $i},4);
1041 $r.='</td>';
1042 $both_side=0;
1043 if ($g_parameter->MY_TVA_USE == 'Y') {
1044 $r.='<td class="num">';
1045 $r.=$oTva->get_parameter('label');
1046 $r.='</td>';
1047 $both_side=$oTva->get_parameter("both_side");
1048 /* warning if tva_computed and given are not the
1049 same */
1050 if (bcsub($tva_item, $tva_computed) != 0 && ! ($tva_item == 0 && $both_side == 1)) {
1051 $r.='<td style="background-color:red" class="num">';
1053 $r.='<a href="#" class="error" style="display:inline" title="' . _("Attention Différence entre TVA calculée et donnée") . '">'
1054 . nbm($tva_item) . '<a>';
1055 } else {
1056 $r.='<td class="num">';
1057 $r.=nbm($tva_item);
1058 }
1059 $r.='</td>';
1060 $r.='<td class="num">';
1061 $r.=nbm($amount);
1062 $r.='</td>';
1063 $tot_row = bcadd($tva_item, $amount);
1064 $r.=td(nbm($tot_row), 'class="num"');
1065 } else {
1066 $r.='<td class="num">';
1067 $r.=nbm($amount);
1068 $r.='</td>';
1069 }
1070 // encode the pa
1071 if ($g_parameter->MY_ANALYTIC != 'nu'
1072 && $g_parameter->match_analytic($fiche->strAttribut(ATTR_DEF_ACCOUNT))==TRUE) { // use of AA
1073 // show form
1074 $anc_op = new Anc_Operation($this->db);
1075 $null = ($g_parameter->MY_ANALYTIC == 'op') ? 1 : 0;
1076 $r.='<td>';
1077 $p_mode = ($p_summary == false) ? 1 : 0;
1078 $p_array['pa_id'] = $a_anc;
1079 /* op is the operation it contains either a sequence or a jrnx.j_id */
1080 $r.=HtmlInput::hidden('op[]=', $i);
1081 $r.=$anc_op->display_form_plan($p_array, $null, $p_mode, $i, round($amount,2));
1082 $r.='</td>';
1083 }
1084
1085
1086 $r.='</tr>';
1087 } // end loop item
1088 //
1089 // Add the sum
1090 $decalage=($g_parameter->MY_TVA_USE == 'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
1091 $tot = bcadd($tot_amount, $tot_tva, 2);
1092 $tot_eur=round(bcdiv($tot, $p_currency_rate),2);
1093 $tot_str=nbm($tot);
1094 $str_tot=_('Totaux');
1095
1096 // Get currency code
1097 $default_currency=new Acc_Currency($this->db,0);
1098 $str_code=$default_currency->get_code();
1099 if ( $p_currency_code != 0 ) {
1100 $acc_currency=new Acc_Currency($this->db);
1101 $acc_currency->set_id($p_currency_code);
1102 $str_code=$acc_currency->get_code();
1103 }
1104 // Format amount
1106 $tot_tva=nbm($tot_tva);
1107 $rate=_("Taux ");
1108if ( $g_parameter->MY_TVA_USE=="Y") {
1109 $r.=<<<EOF
1110 <tr class="highlight">
1111 {$decalage}
1112 <td>
1113 {$str_tot} {$str_code}
1114 </td>
1115 <td class="num">
1116 {$tot_tva}
1117 </td>
1118 <td class="num">
1119 {$tot_amount}
1120 </td>
1121 <td class="num">
1122 {$tot_str} {$str_code}
1123 </td>
1124 </tr>
1125EOF;
1126 if ($p_currency_code !=0) {
1127 $sql_currency=new Currency_SQL($this->cn,0);
1128 $iso_code=$sql_currency->getp("cr_code_iso");
1129
1130 $r.=<<<EOF
1131 <tr class="highlight">
1132 {$decalage}
1133 <td>
1134
1135 </td>
1136 <td class="num">
1137
1138 </td>
1139 <td class="num">
1140 {$rate} {$p_currency_rate}
1141 </td>
1142 <td class="num">
1143 {$tot_eur} {$iso_code}
1144 </td>
1145 </tr>
1146EOF;
1147 }
1148
1149 } else {
1150 $sql_currency=new Currency_SQL($this->cn,$p_currency_code);
1151 $str_code=$sql_currency->getp("cr_code_iso");
1152 $sql_currencydefault=new Currency_SQL($this->cn,0);
1153 $iso_code=$sql_currencydefault->getp("cr_code_iso");
1154 // without VAT
1155 $r.=<<<EOF
1156 <tr class="highlight">
1157 {$decalage}
1158 <td>
1159 {$str_tot} {$str_code}
1160 </td>
1161 <td class="num">
1162
1163 </td>
1164 <td class="num">
1165
1166 </td>
1167 <td class="num">
1168 {$tot_str} {$str_code}
1169 </td>
1170 </tr>
1171 <tr class="highlight">
1172 {$decalage}
1173 <td>
1174 </td>
1175 <td>
1176
1177 </td>
1178 <td>
1179 {$rate} {$p_currency_rate}
1180 </td>
1181 <td class="num">
1182 {$tot_eur} {$iso_code}
1183 </td>
1184 </tr>
1185EOF;
1186 }
1187 $r.='</table>';
1188 $r.='</p>';
1189 if ($g_parameter->MY_ANALYTIC != 'nu' && ! $p_summary) // use of AA
1190 $r.='<input type="button" class="button" value="' . _('Vérifiez Imputation Analytique') . '" onClick="verify_ca(\'\');">';
1191 $r.='<div id="total_div_id" >';
1192 $r.='<h2 class="h-section">Totaux</h2>';
1193 $other_tax_label="";
1195 if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
1196 $other_tax_label=_("Autre taxe");
1197 $other_tax_amount=htmlspecialchars($p_array['other_tax_amount']);
1198 }
1199 /* use VAT */
1200 if ($g_parameter->MY_TVA_USE == 'Y') {
1201 $r.='<table>';
1202 $r.='<tr><td>Total HTVA</td>';
1203 $r.=td(hb($tot_amount ),'class="num"');
1204 foreach ($tva as $i => $value) {
1205 $oTva=Acc_Tva::build($this->cn, $i);
1206 $oTva->load();
1207
1208 $r.='<tr><td> TVA ' . $oTva->get_parameter('label').'</td>';
1209 $r.=td(hb(nbm($tva[$i])),'class="num"');
1210 }
1211 $r.='<tr>'.td(_('Total TVA')).td(hb($tot_tva),'class="num"');
1212 if ( ! empty($other_tax_label) ) {
1213 $r.='<tr>'.td($other_tax_label).td(hb($other_tax_amount),'class="num"');
1214 }
1215 if ( $other_tax_amount!="") {$tot=bcadd($tot,$other_tax_amount,2);}
1216 $r.='<tr>'.td(_('Total TVAC')).td(hb($tot),'class="num"');
1217 $r.='</table>';
1218 } else {
1219 if ( ! empty($other_tax_label) ) {
1220 $r.='<tr>'.td($other_tax_label).td(hb($other_tax_amount),'class="num"');
1221 }
1222 if ( $other_tax_amount!="") {$tot=bcadd($tot,$other_tax_amount,2);}
1223 $r.='<br>Total '.hb($tot);
1224 }
1225 $r.='</div>';
1226
1227
1228 /* Add hidden */
1229 $r.=HtmlInput::hidden('e_client', $e_client);
1230 $r.=HtmlInput::hidden('nb_item', $nb_item);
1231 $r.=HtmlInput::hidden('p_jrn', $p_jrn);
1232 $r.=HtmlInput::hidden('jrn_note_input',h($p_array['jrn_note_input']));
1233 $mt = microtime(true);
1234 $r.=HtmlInput::hidden('mt', $mt);
1235 $r.=HtmlInput::post_to_hidden(['p_currency_rate','p_currency_code']);
1236
1237 if (isset($period))
1238 {
1239 $r.=HtmlInput::hidden('period', $period);
1240 }
1241 /* \todo comment les types hidden gérent ils des contenus avec des quotes, double quote ou < > ??? */
1242 $r.=HtmlInput::hidden('e_comm', $e_comm);
1243 $r.=HtmlInput::hidden('e_date', $e_date);
1244 $r.=HtmlInput::hidden('e_ech', $e_ech);
1245 $r.=HtmlInput::hidden('e_pj', $e_pj);
1246 $r.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
1247 if ( $this->has_other_tax() && isset($p_array["other_tax"])) {
1248 $r.=HtmlInput::hidden("other_tax",$p_array['other_tax']);
1249 $r.=HtmlInput::hidden("other_tax_amount",$p_array['other_tax_amount']);
1250 }
1251 $e_mp = (isset($e_mp)) ? $e_mp : 0;
1252 $r.=HtmlInput::hidden('e_mp', $e_mp);
1253
1254 if ( isset($repo) ) {
1255 // Show the available repository
1256 $r.= $this->select_depot($p_summary,$repo);
1257 }
1258
1259 /* if the paymethod is not 0 and if a quick code is given */
1260 if ($e_mp != 0 && noalyss_strlentrim(${'e_mp_qcode_' . $e_mp}) != 0) {
1261 $r.=HtmlInput::hidden('e_mp_qcode_' . $e_mp, ${'e_mp_qcode_' . $e_mp});
1262 $r.=HtmlInput::hidden('acompte', $acompte);
1263 $r.=HtmlInput::hidden('e_comm_paiement', $e_comm_paiement);
1264 /* needed for generating a invoice */
1265 $r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
1266 $r.=HtmlInput::hidden('mp_date', ${'mp_date'});
1267
1268 $fname = new Fiche($this->db);
1269 $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
1270 $r.='<h2 class="h-section">' . "Payé par " . ${'e_mp_qcode_' . $e_mp} .
1271 " le ".${"mp_date"}.
1272 " " . $fname->getName() . '</h2> ' . '<p class="decale">' . _('Déduction acompte ') . h($acompte) . '</p>' .
1273 _('Libellé :') . h($e_comm_paiement) ;
1274 $r.='<br>';
1275 }
1276
1277 $r.=HtmlInput::hidden('jrn_type', $jrn_type);
1278 for ($i = 0; $i < $nb_item; $i++) {
1279 $r.=HtmlInput::hidden("e_march" . $i, ${"e_march" . $i});
1280 if (isset(${"e_march" . $i . "_label"}))
1281 $r.=HtmlInput::hidden("e_march" . $i . "_label", ${"e_march" . $i . "_label"});
1282 $r.=HtmlInput::hidden("e_march" . $i . "_price", ${"e_march" . $i . "_price"});
1283 if ($g_parameter->MY_TVA_USE == 'Y') {
1284 $r.=HtmlInput::hidden("e_march" . $i . "_tva_id", ${"e_march" . $i . "_tva_id"});
1285 $r.=HtmlInput::hidden("e_march" . $i . "_tva_amount", ${"e_march" . $i . "_tva_amount"});
1286 }
1287 $r.=HtmlInput::hidden("e_quant" . $i, ${"e_quant" . $i});
1288 }
1289 /*
1290 * warning if the amount is positive and expecting a negative one
1291 */
1292 $negative=$this->display_negative_warning($tot);
1293 if ( $negative != "") {
1294 $r.=span($negative,'class="warning" ');
1295 }
1296 return $r;
1297 }
hb($p_string)
Definition ac_common.php:53
span($p_string, $p_extra='')
Definition ac_common.php:43
noalyss_strlentrim($p_string)
tr($p_string, $p_extra='')
Definition ac_common.php:88
td($p_string='', $p_extra='')
surround the string with td
Definition ac_common.php:83
nbm($p_number, $p_dec=2)
format the number with a sep.
global $g_parameter
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$op
h( $row[ 'oa_description'])
$jr_id
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
$input_from cn
_("actif, passif,charge,...")
select_depot($p_readonly, $p_repo)
Let you select the repository before confirming a sale or a purchase.
warn_manual_receipt($p_array)
warn if the suggested receipt and receipt are different , it means that the user tried to number hims...
get_name()
Return the name of a ledger.
display_negative_warning($p_amount)
If the amount is positive and the ledger expects a negative amount, il will return the saved warning.
has_other_tax()
returns true if the ledger has an additional tax
check_periode()
Check if a Dossier is using the check on the periode, if true than the user has to enter the date and...
static build($db, $p_code)
retrieve TVA rate thanks the code that could be the tva_id or tva_code.
static hidden($p_array)
return an HTML string containing hidden input type to hold the differant PA_ID
static hidden($p_name, $p_value, $p_id="")
static post_to_hidden($array)
transform $_POST data to hidden
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
if( $g_parameter->MY_PJ_SUGGEST=='Y') $e_date
$other_tax_amount
Definition compute.php:88
const ATTR_DEF_ADRESS
Definition constant.php:223
const ATTR_DEF_NAME
Definition constant.php:216
const ATTR_DEF_CP
Definition constant.php:224
const ATTR_DEF_CITY
Definition constant.php:229
const ATTR_DEF_ACCOUNT
Definition constant.php:215
const UPDRECEIPT
$jrn_type[]
$SecUser db
$str_code
$date_limit

References $acompte, $amount, $anc, $date_limit, $default_currency, $e_date, $fiche, $g_parameter, $g_user, $i, $jr_id, $jrn_type, $op, $other_tax_amount, $p_array, $p_jrn, $r, $repo, $span, $str_code, $tot, $tot_amount, $value, _, ATTR_DEF_ACCOUNT, ATTR_DEF_ADRESS, ATTR_DEF_CITY, ATTR_DEF_CP, ATTR_DEF_NAME, Acc_Tva\build(), Acc_Ledger\check_periode(), cn, db, Acc_Ledger\display_negative_warning(), Acc_Ledger\get_name(), h, Acc_Ledger\has_other_tax(), hb(), Anc_Plan\hidden(), Icon_Action\infobulle(), nbm(), noalyss_strlentrim(), Acc_Ledger\select_depot(), span(), td(), tr(), UPDRECEIPT, and Acc_Ledger\warn_manual_receipt().

+ Here is the call graph for this function:

◆ extra_info()

Acc_Ledger_Sale::extra_info ( )

the function extra info allows to

  • add a attachment
  • generate an invoice
  • insert extra info
    Returns
    string

Definition at line 1306 of file acc_ledger_sale.class.php.

1306 {
1307 $r = '<div id="facturation_div_id" style="height:185px;height:10rem">';
1308 // check for upload piece
1309 $file = new IFile();
1310 $file->table = 0;
1311 $file->setAlertOnSize(true);
1312 $r.='<p class="decale">';
1313 $r.=_("Ajoutez une pièce justificative ");
1314 $r.=$file->input("pj", "");
1315
1316 if ($this->db->count_sql("select md_id,md_name from document_modele where md_affect='VEN' ") > 0) {
1317
1318
1319 $r.=_('ou générer une facture') . ' <input type="checkbox" name="gen_invoice" CHECKED>';
1320 // We propose to generate the invoice and some template
1321 $doc_gen = new ISelect();
1322 $doc_gen->name = "gen_doc";
1323 $doc_gen->value = $this->db->make_array(
1324 "select md_id,md_name " .
1325 " from document_modele where md_affect='VEN' order by 2");
1326 $r.=$doc_gen->input() . '<br>';
1327 }
1328 $r.='<br>';
1329 $obj = new IText();
1330 $r.=_('Numero de bon de commande : ') . $obj->input('bon_comm') . '<br>';
1331 $r.=_('Communication ou autre information : ') . $obj->input('other_info') . '<br>';
1332 $r.='</p>';
1333 $r.='</div>';
1334 return $r;
1335 }

References $file, $obj, $r, _, and db.

◆ get_detail_sale()

Acc_Ledger_Sale::get_detail_sale ( $p_from,
$p_end,
$p_filter_operation = 'all' )

Retrieve data from the view v_detail_sale , gives all the row of an operation.

Remarks
$g_user connected user
Parameters
$p_fromjrn.jr_tech_per from
type$p_endjrn.jr_tech_per to
$p_filter_operationvalid option : all, paid, unpaid
Returns
type

Definition at line 1699 of file acc_ledger_sale.class.php.

1700 {
1701 global $g_user;
1702 // Journal valide
1703 if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide");
1704
1705 // Securite
1706 if ( $g_user->get_ledger_access($this->id) == 'X' ) return null;
1707
1708 switch ( $p_filter_operation)
1709 {
1710 case 'all':
1711 $sql_filter="";
1712 break;
1713 case 'paid':
1714 $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) ";
1715 break;
1716 case 'unpaid':
1717 $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) ";
1718 break;
1719 default:
1720 throw new Exception(_("Filtre invalide",5));
1721
1722 }
1723 // get the data from the view
1724 $sql = "select *
1725 from v_detail_sale
1726 where
1727 jr_def_id = $1
1728 and jr_date >= (select p_start from parm_periode where p_id = $2)
1729 {$sql_filter}
1730 and jr_date <= (select p_end from parm_periode where p_id = $3) "
1731 .' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
1732 $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
1733 return $ret;
1734 }
$sql_filter
Definition preod.inc.php:43

References $g_user, $p_end, $ret, $sql, $sql_filter, _, and db.

◆ heading_detail_sale()

static Acc_Ledger_Sale::heading_detail_sale ( )
static

compute an array with the heading cells for the details, used for the export in CSV

Returns
array

Definition at line 1740 of file acc_ledger_sale.class.php.

1741 {
1742 $array['jr_id'] = _('Numéro opération');
1743 $array['jr_date'] = _('Date');
1744 $array['jr_date_paid'] = _('Date paiement');
1745 $array['jr_ech'] = _('Date échéance');
1746 $array['jr_tech_per'] = _('Période');
1747 $array['jr_comment'] = _('Libellé');
1748 $array['jr_pj_number'] = _('Pièce');
1749 $array['jr_internal'] = _('Interne');
1750 $array['jr_def_id'] = _('Code journal');
1751 $array['j_poste'] = _('Poste');
1752 $array['j_text'] = _('Commentaire');
1753 $array['j_qcode'] = _('Code Item');
1754 $array['jr_rapt'] = _('Payé');
1755 $array['item_card'] = _('N° item');
1756 $array['item_name'] = _('Nom fiche');
1757 $array['qs_client'] = _('N° fiche fournisseur');
1758 $array['tiers_name'] = _('Nom fournisseur');
1759 $array['quick_code'] = _('Code fournisseur');
1760 $array['tva_label'] = _('Nom TVA');
1761 $array['tva_comment'] = _('Commentaire TVA');
1762 $array['tva_both_side'] = _('TVA annulée');
1763 $array['vat_sided'] = _('TVA Non Payé');
1764 $array['vat_code'] = _('Code TVA');
1765 $array['vat'] = _('Montant TVA');
1766 $array['price'] = _('Total HTVA');
1767 $array['quantity'] = _('quantité');
1768 $array['price_per_unit'] = _('PU');
1769 $array['htva'] = _('HTVA Opération');
1770 $array['tot_vat'] = _('TVA Opération');
1771 $array['tot_vat_np'] = _('TVA ND');
1772 $array['other_tax'] = _("Autre taxe");
1773 $array['oc_amount'] = _('Mont. Devise');
1774 $array['oc_vat_amount'] = _('Mont. TVA Devise');
1775 $array['cr_code_iso'] = _('Devise');
1776
1777
1778 return $array;
1779 }

References $array, and _.

◆ input()

Acc_Ledger_Sale::input ( $p_array = null,
$p_readonly = 0 )

display the form for entering data for invoice,

Parameters
$p_arrayis null or you can put the predef operation or the $_POST
Returns
HTML string

Reimplemented from Acc_Ledger.

Definition at line 1345 of file acc_ledger_sale.class.php.

1345 {
1346 global $g_parameter, $g_user;
1347 // load ledger definition
1348 $this->load();
1349 $http=new HttpInput();
1350 $http->set_array([]);
1351 if ($p_array != null) {
1352 extract($p_array, EXTR_SKIP);
1353 $http->set_array($p_array);
1354 }
1355 if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
1356 $flag_tva = $g_parameter->MY_TVA_USE;
1357 /* Add button */
1358
1359 $str_add_button_tiers = "";
1360 $add_card=FALSE;
1361 if ($g_user->check_action(FICADD) == 1) {
1362 $add_card=TRUE;
1363 $str_add_button_tiers = $this->add_card("deb", "e_client");
1364 }
1365
1366 // The first day of the periode
1367 $oPeriode = new Periode($this->db);
1368 list ($l_date_start, $l_date_end) = $oPeriode->get_date_limit($g_user->get_periode());
1369 if ($g_parameter->MY_DATE_SUGGEST == 'Y')
1370 $op_date = (!isset($e_date) ) ? $l_date_start : $e_date;
1371 else
1372 $op_date = (!isset($e_date) ) ? '' : $e_date;
1373
1374 $e_ech = (isset($e_ech)) ? $e_ech : "";
1375 $e_comm = (isset($e_comm)) ? $e_comm : "";
1376
1377 $r = '';
1378 $r.=dossier::hidden();
1379 $f_legend = _('Client');
1380
1381 $Echeance = new IDate();
1382 $Echeance->setReadOnly(false);
1383
1384 $Echeance->tabindex = 2;
1386 $f_echeance = $Echeance->input('e_ech', $e_ech, _('Echéance') . $label);
1387 $Date = new IDate();
1388 $Date->setReadOnly(false);
1389
1390 $f_date = $Date->input("e_date", $op_date);
1391
1392 $f_periode = '';
1393 // Periode
1394 //--
1395 if ($this->check_periode() == true) {
1396 $l_user_per = $g_user->get_periode();
1397 $def = (isset($periode)) ? $periode : $l_user_per;
1398
1399 $period = new IPeriod("period");
1400 $period->user = $g_user;
1401 $period->cn = $this->db;
1402 $period->value = $def;
1403 $period->type = OPEN;
1404 try {
1405 $l_form_per = $period->input();
1406 } catch (Exception $e) {
1407 if ($e->getCode() == 1) {
1408 throw new Exception( _("Aucune période ouverte") );
1409 }
1410 }
1412 $f_periode = '<td>' . _("Période comptable") . "</td> <td> $label " . $l_form_per . '</td>';
1413 }
1414 /* if we suggest the next pj, then we need a javascript */
1415 $add_js = "";
1416 if ($g_parameter->MY_PJ_SUGGEST != 'N') {
1417 $add_js = "update_receipt();";
1418 }
1419 if ($g_parameter->MY_DATE_SUGGEST == 'Y') {
1420 $add_js.='get_last_date();';
1421 }
1422 $add_js.='update_name();';
1423 $add_js.='update_pay_method();';
1424 $add_js.='update_row("sold_item");';
1425 $add_js.='update_other_tax();';
1426 $add_js.='update_visibility_quantity();';
1427
1428 $wLedger = $this->select_ledger('VEN', 2,FALSE);
1429 if ($wLedger == null)
1430 throw new Exception(_('Pas de journal disponible'));
1431 $wLedger->table = 0;
1432 $wLedger->javascript = "onChange='update_predef(\"ven\",\"f\",\"".$_REQUEST['ac']."\");$add_js'";
1433 $wLedger->label = " Journal " . Icon_Action::infobulle(2);
1434
1435 $f_jrn = $wLedger->input();
1436
1437 $Commentaire = new IText();
1438 $Commentaire->table = 0;
1439 $Commentaire->setReadOnly(false);
1440 $Commentaire->size = (empty($e_comm))?60:strlen($e_comm)+5;
1441 $Commentaire->size = ($Commentaire->size<60)?60:$Commentaire->size;
1442 $Commentaire->tabindex = 3;
1443
1445
1446 $f_desc = $Commentaire->input("e_comm", $e_comm) ;
1447 // PJ
1448 //--
1449 /* suggest PJ ? */
1450 $default_pj = '';
1451 if ($g_parameter->MY_PJ_SUGGEST != 'N') {
1452 $default_pj = $this->guess_pj();
1453 }
1454
1455 $pj = new IText();
1456 if ( $g_parameter->MY_PJ_SUGGEST=='A'||$g_user->check_action(UPDRECEIPT)==0)
1457 {
1458 $pj->setReadOnly(true);
1459 $pj->id="e_pj";
1460 }
1461
1462 $pj->table = 0;
1463 $pj->name = "e_pj";
1464 $pj->size = 10;
1465 $pj->value = (isset($e_pj)) ? $e_pj : $default_pj;
1466 $f_pj = $pj->input() . HtmlInput::hidden('e_pj_suggest', $default_pj);
1467 // Display the customer
1468 //--
1469 $fiche = 'deb';
1470
1471 // Save old value and set a new one
1472 //--
1473 $e_client = ( isset($e_client) ) ? $e_client : "";
1474 $e_client_label = "&nbsp;"; //str_pad("",100,".");
1475 // retrieve e_client_label
1476 //--
1477
1478 if (noalyss_strlentrim($e_client) != 0) {
1479 $fClient = new Fiche($this->db);
1480 $fClient->get_by_qcode($e_client);
1481 $e_client_label = $fClient->strAttribut(ATTR_DEF_NAME) . ' ' .
1482 ' Adresse : ' . $fClient->strAttribut(ATTR_DEF_ADRESS) . ' ' .
1483 $fClient->strAttribut(ATTR_DEF_CP) . ' ' .
1484 $fClient->strAttribut(ATTR_DEF_CITY) . ' ';
1485 }
1486
1487 $W1 = new ICard();
1488 $W1->label = "Client " . Icon_Action::infobulle(0);
1489 $W1->name = "e_client";
1490 $W1->tabindex = 3;
1491 $W1->value = $e_client;
1492 $W1->table = 0;
1493 $W1->set_dblclick("fill_ipopcard(this);");
1494 $W1->set_attribute('ipopup', 'ipopcard');
1495
1496 // name of the field to update with the name of the card
1497 $W1->set_attribute('label', 'e_client_label');
1498 // name of the field to update with the name of the card
1499 $W1->set_attribute('typecard', 'deb');
1500
1501 // Add the callback function to filter the card on the jrn
1502 $W1->set_callback('filter_card');
1503 $W1->set_function('fill_data');
1504 $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
1505 $f_client_qcode = $W1->input();
1506 $client_label = new ISpan();
1507 $client_label->table = 0;
1508 $f_client = $client_label->input("e_client_label", $e_client_label);
1509 $f_client_bt = $W1->search();
1510
1511
1512 // Record the current number of article
1513 $Hid = new IHidden();
1514 $p_article = ( isset($nb_item)) ? $nb_item : $this->get_min_row();
1515 $r.=$Hid->input("nb_item", $p_article);
1516 $p_article = ($p_article < $this->get_min_row()) ? $this->get_min_row() : $p_article;
1517
1518
1519 $f_legend_detail = _("Détail articles vendus");
1520
1521 // For each article
1522 //--
1523 for ($i = 0; $i < $p_article; $i++) {
1524 // Code id, price & vat code
1525 //--
1526 $march = (isset(${"e_march$i"})) ? ${"e_march$i"} : "";
1527 $march_price = (isset(${"e_march" . $i . "_price"})) ? ${"e_march" . $i . "_price"} : "" ;
1528 if ($flag_tva == 'Y') {
1529 $march_tva_id = (isset(${"e_march$i" . "_tva_id"})) ? ${"e_march$i" . "_tva_id"} : "";
1530 $march_tva_amount = (isset(${"e_march$i" . "_tva_amount"})) ? ${"e_march$i" . "_tva_amount"} : "";
1531 }
1532 $march_label = (isset(${"e_march" . $i . "_label"})) ? ${"e_march" . $i . "_label"} : "";
1533
1534 // retrieve the tva label and name
1535 //--
1536 if (noalyss_strlentrim($march) != 0 && noalyss_strlentrim($march_label) == 0) {
1537 $fMarch = new Fiche($this->db);
1538 $fMarch->get_by_qcode($march);
1539 $march_label = $fMarch->strAttribut(ATTR_DEF_NAME);
1540 if ($flag_tva == 'Y') {
1541 if (!(isset(${"e_march$i" . "_tva_id"})))
1542 $march_tva_id = $fMarch->strAttribut(ATTR_DEF_TVA);
1543 }
1544 }
1545 // Show input
1546 //--
1547 $W1 = new ICard();
1548 $W1->label = "";
1549 $W1->name = "e_march" . $i;
1550 $W1->value = $march;
1551 $W1->table = 0;
1552 $W1->set_attribute('typecard', 'cred');
1553 $W1->set_dblclick("fill_ipopcard(this);");
1554 $W1->set_attribute('ipopup', 'ipopcard');
1555
1556 // name of the field to update with the name of the card
1557 $W1->set_attribute('label', 'e_march' . $i . '_label');
1558 // name of the field with the price
1559 $W1->set_attribute('price', 'e_march' . $i . '_price');
1560 // name of the field with the TVA_ID
1561 $W1->set_attribute('tvaid', 'e_march' . $i . '_tva_id');
1562 // Add the callback function to filter the card on the jrn
1563 $W1->set_callback('filter_card');
1564 $W1->set_function('fill_data');
1565 $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
1566
1567 $W1->readonly = false;
1568
1569 $array[$i]['quick_code'] = $W1->input();
1570 $array[$i]['bt'] = $W1->search();
1571 $array[$i]['card_add']=($add_card==TRUE)?$this->add_card("cred", $W1->id):"";
1572 // For computing we need some hidden field for holding the value
1573 $array[$i]['hidden'] = '';
1574 if ($flag_tva == 'Y')
1575 $array[$i]['hidden'].=HtmlInput::hidden('tva_march' . $i, 0);
1576
1577 $htva = new INum('htva_march' . $i);
1578 $htva->readOnly = 1;
1579 $htva->value = 0;
1580 $array[$i]['htva'] = $htva->input();
1581
1582 if ($g_parameter->MY_TVA_USE == 'Y')
1583 $tvac = new INum('tvac_march' . $i);
1584 else
1585 $tvac = new IHidden('tvac_march' . $i);
1586
1587 $tvac->readOnly = 1;
1588 $tvac->value = 0;
1589 $array[$i]['tvac'] = $tvac->input();
1590
1591 if ( $g_parameter->MY_UPDLAB == 'Y')
1592 {
1593 $Span=new IText("e_march".$i."_label");
1594 $Span->style='class="input_text label_item"';
1595 } else
1596 {
1597 $Span=new ISpan("e_march".$i."_label");
1598 $Span->extra='class="label_item"';
1599 }
1600 $Span->value = $march_label;
1601 $Span->setReadOnly(false);
1602 // card's name, price
1603 //--
1604 $array[$i]['denom'] = $Span->input("e_march" . $i . "_label", $march_label);
1605 // price
1606 $Price = new INum();
1607 $Price->setReadOnly(false);
1608 $Price->size = 9;
1609 $Price->javascript = "onblur=\"format_number(this,4);clean_tva($i);compute_ledger($i)\"";
1610 $array[$i]['pu'] = $Price->input("e_march" . $i . "_price", $march_price);
1611 $array[$i]['tva'] = '';
1612 $array[$i]['amount_tva'] = '';
1613 // if tva is not needed then no tva field
1614 if ($flag_tva == 'Y') {
1615 // vat label
1616 //--
1617 $Tva = new ITva_Popup($this->db);
1618 $Tva->in_table = true;
1619 $Tva->set_attribute('compute', $i);
1620 $Tva->set_filter("sale");
1621
1622 $Tva->js = 'onblur="clean_tva(' . $i . ');compute_ledger(' . $i . ')"';
1623 $Tva->value = $march_tva_id;
1624 $array[$i]['tva'] = $Tva->input("e_march$i" . "_tva_id");
1625 // vat amount
1626 //--
1627 $wTva_amount = new INum();
1628 $wTva_amount->readOnly = false;
1629 $wTva_amount->size = 6;
1630 $wTva_amount->javascript = "onblur='format_number(this);compute_ledger($i)'";
1631 $array[$i]['amount_tva'] = $wTva_amount->input("e_march" . $i . "_tva_amount", $march_tva_amount);
1632 }
1633 // quantity
1634 //--
1635 $quant = (isset(${"e_quant$i"})) ? ${"e_quant$i"} : "1";
1636 $Quantity = new INum();
1637
1638 $Quantity->setReadOnly(false);
1639 $Quantity->size = 8;
1640 $Quantity->javascript = "onchange=\"format_number(this,2);clean_tva($i);compute_ledger($i);\"";
1641 $array[$i]['quantity'] = $Quantity->input("e_quant" . $i, $quant);
1642 }// foreach article
1643 $f_type = _('Client');
1644
1645 // Currency
1646 $currency_select = $this->CurrencyInput("currency_code", "p_currency_rate" , "p_currency_euro");
1647 $currency_select->selected=$http->extract('p_currency_code','string',0);
1648
1649 $currency_input=new INum("p_currency_rate");
1650 $currency_input->id="p_currency_rate";
1651 $currency_input->prec=8;
1652 $currency_input->value=$http->extract('p_currency_rate','string',1);
1653 $currency_input->javascript='onchange="format_number(this,4);CurrencyCompute(\'p_currency_rate\',\'p_currency_euro\');"';
1654
1655 $currency=new Acc_Currency($this->db,0);
1656
1657 //
1658 // Button for template operation
1659 //
1660 ob_start();
1661 echo '<div id="predef_form">';
1662 echo HtmlInput::hidden('p_jrn_predef', $this->id);
1663 $op=new Pre_operation($this->db);
1664 $op->set_jrn_type("VEN");
1665 $op->set_p_jrn($this->id);
1666 $op->set_od_direct('f');
1667 $url=http_build_query(array('p_jrn_predef'=>$this->id, 'ac'=>$http->request('ac'),
1668 'gDossier'=>dossier::id()));
1669 echo $op->form_get('do.php?'.$url);
1670 echo '</div>';
1671 $str_op_template=ob_get_contents();
1672 ob_end_clean();
1673
1674 ob_start();
1675 require_once NOALYSS_TEMPLATE.'/form_ledger_detail.php';
1676 $form_ledger_detail=ob_get_contents();
1677 ob_end_clean();
1678
1679 $r.=$form_ledger_detail;
1680
1681 // Set correctly the REQUEST param for jrn_type
1682 $r.=HtmlInput::hidden('jrn_type', 'VEN');
1684 $r.= create_script("$('" . $Date->id . "').focus()");
1685 $r.='<div id="additional_tax_div">';
1686 $r.=$this->input_additional_tax();
1687 $r.='</div>';
1688 return $r;
1689 }
CurrencyInput($p_currency_code, $p_currency_rate, $p_eur_amount)
Create a select from value for currency and add javascript to update $p_currency_rate and $p_eur_amou...
select_ledger($p_type="ALL", $p_access=3, $enable=TRUE)
Show a select list of the ledgers you can access in writing, reading or simply accessing.
input_additional_tax()
form : display additional tax available for this ledger and value, set 2 values : checkbox if tax app...
add_card($p_filter, $p_id_update)
Return a button to create new card, depending of the ledger.
$db
!< jrn_def.jrn_def_id
guess_pj()
guess what the next pj should be
static ledger_add_item($p_ledger)
Build a HTML string for adding multiple rows.
$def
show a form for quick_writing
const OPEN
Definition constant.php:201
const ATTR_DEF_TVA
Definition constant.php:221
const FICADD
$oPeriode
Definition do.php:156
create_script($p_string)
create the HTML for adding the script tags around of the script

References $array, $currency, Acc_Ledger\$db, $def, $e, $e_date, $fiche, $g_parameter, $g_user, $http, $i, $label, $op, $oPeriode, $p_array, $p_readonly, $periode, $r, $url, $wLedger, _, Acc_Ledger\add_card(), ATTR_DEF_ADRESS, ATTR_DEF_CITY, ATTR_DEF_CP, ATTR_DEF_NAME, ATTR_DEF_TVA, Acc_Ledger\check_periode(), create_script(), Acc_Ledger\CurrencyInput(), db, FICADD, Acc_Ledger\get_min_row(), Acc_Ledger\guess_pj(), Icon_Action\infobulle(), Acc_Ledger\input_additional_tax(), Html_Input_Noalyss\ledger_add_item(), noalyss_strlentrim(), OPEN, Acc_Ledger\select_ledger(), and UPDRECEIPT.

+ Here is the call graph for this function:

◆ insert()

Acc_Ledger_Sale::insert ( $p_array = null)

insert into the database, it calls first the verify function, store the value of the inserted operation in $this->jr_id and this->jr_internal

It generates the document if gen_invoice is set and save the middle of payment if any ($e_mp)

It also create a second operation if there is a payment

Parameters
$p_arrayis usually $_POST or a predefined operation
Returns
string : internal number
Note
throw an Exception

if the given receipt number is equal to one computed then increment

Date

Definition at line 267 of file acc_ledger_sale.class.php.

267 {
268 global $g_parameter,$g_user;
269 // load ledger definition
270 $this->load();
271 extract($p_array, EXTR_SKIP);
272 $this->verify($p_array);
273
274 $group = $this->db->get_next_seq("s_oa_group"); /* for analytic */
275 $seq = $this->db->get_next_seq('s_grpt');
276 $this->id = $p_jrn;
277 $internal = $this->compute_internal_code($seq);
278 $this->internal = $internal;
279
280 $oPeriode = new Periode($this->db);
281 $check_periode = $this->check_periode();
282
283 if ($check_periode == true && isset($p_array['period']))
284 $tperiode = $period;
285 else
286 $tperiode = $oPeriode->find_periode($e_date);
287
288 $cust = new Fiche($this->db);
289 $cust->get_by_qcode($e_client);
290 $sposte = $cust->strAttribut(ATTR_DEF_ACCOUNT);
291
292 // if 2 accounts, take only the debit one for the customer
293 //
294 if (strpos($sposte, ',') != 0) {
295 $array = explode(',', $sposte);
296 $poste = $array[0];
297 } else {
298 $poste = $sposte;
299 }
300
301 bcscale(4);
302 try {
303 // variable : $tot_amount : total amount of the sales (credit)
304 $tot_amount = 0;
305 // variable : $tot_tva : total amount of the VAT
306 $tot_tva = 0;
307 // tot debit if item's amount < 0
308 $tot_debit = 0;
309 // variable : $tot_amount_cur : total amount in currency
310 $tot_amount_cur=0;
311
312 $this->db->start();
313 // variable : $tva array that will contain all the VAT Amount
314 $tva = array();
315 // variable : $tva_reverse array that contain all the VAT autoreverse AND negative
316 $tva_reverse = array();
317
318 // find the currency from v_currency_last_value
319 // variable : $currency_rate_ref Acc_Currency , currency object for this operation
320 $currency_rate_ref=new Acc_Currency($this->db, $p_currency_code);
321
322 /* Save all the items without vat */
323 for ($i = 0; $i < $nb_item; $i++) {
324 // variable : $n_both float auto-reverse amount
325 $n_both = 0;
326 if ( empty(${'e_march'.$i}) || empty(${'e_quant'.$i}) ) continue;
327
328 /* First we save all the items without vat */
329 $fiche = new Fiche($this->db);
330 $fiche->get_by_qcode(${"e_march" . $i});
331 $amount_currency = bcmul(${'e_march' . $i . '_price'}, ${'e_quant' . $i});
332
333 // convert amount to currency
334 $amount=bcdiv($amount_currency,$p_currency_rate);
335
337 $tot_amount = round($tot_amount, 2);
338 $acc_operation = new Acc_Operation($this->db);
339 $acc_operation->date = $e_date;
340 $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
341
342 // if 2 accounts, take only the credit one
343 if (strpos($sposte, ',') != 0) {
344 $array = explode(',', $sposte);
345 $poste_val = $array[1];
346 } else {
347 $poste_val = $sposte;
348 }
349
350 $acc_operation->poste = $poste_val;
351 $acc_operation->amount = $amount;
352 $acc_operation->grpt = $seq;
353 $acc_operation->jrn = $p_jrn;
354 $acc_operation->type = 'c';
355 $acc_operation->periode = $tperiode;
356 if ($g_parameter->MY_UPDLAB=='Y')
357 {
358 $acc_operation->desc=strip_tags(${"e_march".$i."_label"});
359 }
360 else
361 {
362 $acc_operation->desc=null;
363 }
364
365 $acc_operation->qcode = ${"e_march" . $i};
366 if ($amount<0)
367 {
368 $tot_debit=round(bcadd($tot_debit, abs($amount)),2);
369 }
370
371 $j_id = $acc_operation->insert_jrnx();
372
373 if ($g_parameter->MY_TVA_USE == 'Y') {
374 /* Compute sum vat */
375 $oTva = Acc_Tva::build($this->db, trim(${'e_march' . $i . '_tva_id'}));
376 $idx_tva =$oTva->get_parameter("id");
377 // variable : $auto_reverse = if the oTVA autoreverse, fetch it once for this item,
378 $auto_reverse=$oTva->get_parameter("both_side");
379
380 $tva_item_currency = ${'e_march' . $i . '_tva_amount'};
381
382 /* if empty then we need to compute it */
383 if (trim($tva_item_currency) == '' || ${'e_march'.$i.'_tva_amount'} == 0) {
384 $tva_item_currency = bcmul($amount, $oTva->get_parameter('rate'));
385 $tva_item=round($tva_item_currency,2);
386 }
387 $tva_item=bcdiv($tva_item_currency,$p_currency_rate);
388 $tva_item=round($tva_item,2);
389
390 $tva[$idx_tva]=(isset($tva[$idx_tva]))?$tva[$idx_tva]:0;
391
392 if ( $auto_reverse == 0)
393 {
394 $tva[$idx_tva]=bcadd($tva_item,$tva[$idx_tva]);
395 $tva[$idx_tva]=round($tva[$idx_tva],2);
396 $tot_tva = bcadd($tva_item, $tot_tva);
397 $tot_tva = round($tot_tva, 2);
398 }
399 else
400 {
401 $n_both = $tva_item;
402 $tva_item_currency = 0;
403 if ($n_both<0)
404 {
405 $tot_debit=round(bcadd($tot_debit, abs($n_both)),2);
406 $tva_reverse[$idx_tva]=(isset($tva_reverse[$idx_tva]))?$tva_reverse[$idx_tva]:0;
407 $tva_reverse[$idx_tva]=bcadd($tva_item,$tva_reverse[$idx_tva]);
408 $tva_reverse[$idx_tva]=round($tva_reverse[$idx_tva],2);
409
410 } else {
411 $tva[$idx_tva]=bcadd($tva_item,$tva[$idx_tva]);
412 $tva[$idx_tva]=round($tva[$idx_tva],2);
413
414 }
415 }
416 }
417
418 /* Save the stock */
419 /* if the quantity is < 0 then the stock increase (return of
420 * material)
421 */
422 $nNeg = (${"e_quant" . $i} < 0) ? -1 : 1;
423
424 // always save quantity but in withStock we can find
425 // what card need a stock management
426 if ($g_parameter->MY_STOCK = 'Y' && isset($repo))
427 {
428 $dir=(${'e_quant'.$i} < 0 ) ? 'd':'c';
429 Stock_Goods::insert_goods($this->db, array('j_id' => $j_id, 'goods' => ${'e_march' . $i}, 'quant' => $nNeg * ${'e_quant' . $i}, 'dir' => $dir, 'repo' => $repo));
430 }
431
432
433 if ($g_parameter->MY_ANALYTIC != "nu" && $g_parameter->match_analytic($poste_val)) {
434 // for each item, insert into operation_analytique */
435 $op = new Anc_Operation($this->db);
436 $op->set_currency_rate($p_currency_rate);
437 $op->oa_group = $group;
438 $op->j_id = $j_id;
439 $op->oa_date = $e_date;
440 $op->oa_debit = 'f';
441 $op->oa_description = sql_string($e_comm);
442 $op->save_form_plan($_POST, $i, $j_id);
443 }
444 if (empty( ${'e_march' . $i . '_price'} ) ) ${'e_march' . $i . '_price'} = 0;
445 if (empty( ${'e_march' . $i } ) ) ${'e_march' . $i } = 0;
446 if (empty( ${'e_quant' . $i } ) ) ${'e_quant' . $i } = 0;
447
448 $price_euro=bcdiv(${'e_march'.$i.'_price'}, $p_currency_rate);
449
450 if ($g_parameter->MY_TVA_USE == 'Y') {
451 /* save into quant_sold */
452 $r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)", array(null, /* 1 */
453 $j_id, /* 2 */
454 ${'e_march' . $i}, /* 3 */
455 ${'e_quant' . $i}, /* 4 */
456 round($amount, 2), /* 5 */
457 $tva_item, /* 6 */
458 $oTva->get_parameter("id"), /* 7 */
459 $e_client, /* 8 */
460 $n_both, /* 9 */
461 $price_euro/* Price /unit */
462 ));
463 } else {
464 $tva_item_currency=0;
465
466 $r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) ", array(null, /* 1 */
467 $j_id, /* 2 */
468 ${'e_march' . $i}, /* 3 */
469 ${'e_quant' . $i}, /* 4 */
470 $amount, // 5
471 0,
472 null,
473 $e_client,
474 0, /* 9 */
475 $price_euro /* Price /unit */
476 ));
477 } // if ( $g_parameter->MY_TVA_USE=='Y') {
478 /*
479 * Insert also in operation_currency
480 */
481 $operation_currency=new Operation_currency_SQL($this->db);
482 $operation_currency->oc_amount=$amount_currency;
483 $operation_currency->oc_vat_amount=$tva_item_currency;
484 $operation_currency->oc_price_unit=${'e_march'.$i.'_price'};
485 $operation_currency->j_id=$j_id;
486 $operation_currency->insert();
487 $tot_amount_cur=round(bcadd($tot_amount_cur,$amount_currency,4),4);
488 $tot_amount_cur=round(bcadd($tot_amount_cur,$tva_item_currency,4),4);
489 }// end loop : save all items
490
491 /*** save other tax ****/
492 if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
493 $row=$this->db->get_row("select ac_id,ac_label,ac_accounting
494 from acc_other_tax
495 where ac_id=$1 ",
496 [$p_array['other_tax']]);
497 if ( ! empty ($row )) {
498 $other_tax_amount=bcmul($p_array['other_tax_amount'],$p_currency_rate);
499 $acc_operation=new Acc_Operation($this->db);
500 $acc_operation->date=$e_date;
501 $acc_operation->poste=$row['ac_accounting'];
502 $acc_operation->amount=$other_tax_amount;
503 $acc_operation->grpt=$seq;
504 $acc_operation->jrn=$p_jrn;
505 $acc_operation->type='c';
506 $acc_operation->periode=$tperiode;
507 $acc_operation->desc=$row['ac_label'];
508 $jrn_tax_sql=new Jrn_Tax_SQL($this->db);
509 $jrn_tax_sql->j_id=$acc_operation->insert_jrnx();
510 $jrn_tax_sql->ac_id=$row['ac_id'];
511 $jrn_tax_sql->pcm_val=$row['ac_accounting'];
512 $jrn_tax_sql->insert();
514 if ( $p_array['other_tax_amount'] < 0 ) {
515 $tot_debit=bcadd($tot_debit,abs($other_tax_amount));
516 }
517 $operation_currency=new Operation_currency_SQL($this->db);
518 $operation_currency->oc_amount=$p_array['other_tax_amount'];
519 $operation_currency->oc_vat_amount=0;
520 $operation_currency->oc_price_unit=0;
521 $operation_currency->j_id=$jrn_tax_sql->j_id;
522 $operation_currency->insert();
523 }
524
525 }
526
527
528 /* save total customer */
529 $cust_amount = bcadd($tot_amount, $tot_tva);
530 $cust_amount = round($cust_amount,2);
531 if ( DEBUGNOALYSS > 1 ) {
532 echo __LINE__." cust_amount $cust_amount<br>";
533 echo __LINE__." tot_amount $tot_amount<br>";
534 echo __LINE__." tot_tva $tot_tva<br>";
535
536 }
537
538 $acc_operation = new Acc_Operation($this->db);
539 $acc_operation->date = $e_date;
540 $acc_operation->poste = $poste;
541 $acc_operation->amount = $cust_amount;
542 $acc_operation->grpt = $seq;
543 $acc_operation->jrn = $p_jrn;
544 $acc_operation->type = 'd';
545 $acc_operation->periode = $tperiode;
546 $acc_operation->qcode = ${"e_client"};
547 if ($cust_amount>0)
548 {
549 $tot_debit=bcadd($tot_debit, $cust_amount);
550 $tot_debit=round($tot_debit, 2);
551 }
552 $let_tiers = $acc_operation->insert_jrnx();
553
554 // --- insert also the currency amount for the customer
555 $operation_currency=new Operation_currency_SQL($this->db);
556 $operation_currency->oc_amount=$tot_amount_cur;
557 $operation_currency->oc_vat_amount=0;
558 $operation_currency->oc_price_unit=0;
559 $operation_currency->j_id=$let_tiers ;
560 $operation_currency->insert();
561
562
563 /**************************************************************************************************
564 * save all vat
565 * $i contains the tva_id and value contains the vat amount
566 * if if ($g_parameter->MY_TVA_USE == 'Y' )
567 ************************************************************************************************** */
568 if ($g_parameter->MY_TVA_USE == 'Y') {
569
570 foreach ($tva as $i => $value) {
571 $oTva = Acc_Tva::build($this->db,$i);
572 $poste_vat = $oTva->get_side('c');
573
574 $cust_amount = bcadd($tot_amount, $tot_tva);
575 $acc_operation = new Acc_Operation($this->db);
576 $acc_operation->date = $e_date;
577 $acc_operation->poste = $poste_vat;
578 $acc_operation->amount = $value;
579 $acc_operation->grpt = $seq;
580 $acc_operation->jrn = $p_jrn;
581 $acc_operation->type = 'c';
582 $acc_operation->periode = $tperiode;
583 if ($value<0)
584 {
585 $tot_debit=bcadd($tot_debit, abs($value));
586 $tot_debit=round($tot_debit, 2);
587 }
588 if ( $oTva->get_parameter("both_side") == 1 && $value ==0 ) continue;
589 $acc_operation->insert_jrnx();
590
591 // if TVA is on both side, we deduce it immediately
592 if ($oTva->get_parameter("both_side") == 1 ) {
593 // $x temp variable is the tva_reverse_account and will be used to check $poste_vat
594 $x=$oTva->get_parameter("tva_reverse_account");
595
596 $poste_vat =(trim($x??"")=="")? $oTva->get_side('d'):$x;
597 if ($poste_vat == '#') $poste_vat=$oTva->get_side('c');
598 $cust_amount = bcadd($tot_amount, $tot_tva);
599 $acc_operation = new Acc_Operation($this->db);
600 $acc_operation->date = $e_date;
601 $acc_operation->poste = $poste_vat;
602 $acc_operation->amount = $value;
603 $acc_operation->grpt = $seq;
604 $acc_operation->jrn = $p_jrn;
605 $acc_operation->type = 'd';
606 $acc_operation->periode = $tperiode;
607 $acc_operation->insert_jrnx();
608 $tot_debit = bcadd($tot_debit, $value);
609 $tot_debit = round($tot_debit, 2);
610 $n_both = $value;
611 }
612
613 }
614 foreach ($tva_reverse as $i => $value) {
615 $oTva = Acc_Tva::build($this->db,$i);
616 $poste_vat = $oTva->get_side('c');
617 if ( $poste_vat == '#')
618 {
619 $poste_vat=$oTva->get_side('d');
620 }
621
622 $acc_operation = new Acc_Operation($this->db);
623 $acc_operation->date = $e_date;
624 $acc_operation->poste = $poste_vat;
625 $acc_operation->amount = $value;
626 $acc_operation->grpt = $seq;
627 $acc_operation->jrn = $p_jrn;
628 $acc_operation->type = 'c';
629 $acc_operation->periode = $tperiode;
630 if ($value<0)
631 {
632 $tot_debit=bcadd($tot_debit, abs($value));
633 $tot_debit=round($tot_debit, 2);
634 }
635 $acc_operation->insert_jrnx();
636
637 // if TVA is on both side, we deduce it immediately
638 $poste_vat = $oTva->get_side('d');
639 if ( $poste_vat == '#')
640 {
641 $poste_vat=$oTva->get_side('c');
642 }
643 $acc_operation = new Acc_Operation($this->db);
644 $acc_operation->date = $e_date;
645 $acc_operation->poste = $poste_vat;
646 $acc_operation->amount = $value;
647 $acc_operation->grpt = $seq;
648 $acc_operation->jrn = $p_jrn;
649 $acc_operation->type = 'd';
650 $acc_operation->periode = $tperiode;
651 $acc_operation->insert_jrnx();
652 $tot_debit = bcadd($tot_debit, $value);
653 $tot_debit = round($tot_debit, 2);
654 $n_both = $value;
655
656 }
657
658 } // if ($g_parameter->MY_TVA_USE=='Y')
659 /*
660 * Balance the amount on D and C , the difference must be inserted as "difference due to a rounded value"
661 * Value are retrieve thanks $seq
662 */
663
664 /* insert into jrn */
665 if ( DEBUGNOALYSS > 1 ) { echo __LINE__." tot_debit ".round($tot_debit,2)."<br>"; }
666 $acc_operation = new Acc_Operation($this->db);
667 $acc_operation->date = $e_date;
668 $acc_operation->echeance = $e_ech;
669 $acc_operation->amount = abs(round($tot_debit, 2));
670 $acc_operation->desc = $e_comm;
671 $acc_operation->grpt = $seq;
672 $acc_operation->jrn = $p_jrn;
673 $acc_operation->periode = $tperiode;
674 $acc_operation->pj = $e_pj;
675 $acc_operation->mt = $mt;
676 $acc_operation->currency_id=$p_currency_code;
677 $acc_operation->currency_rate=$p_currency_rate;
678 $acc_operation->currency_rate_ref=$currency_rate_ref->get_rate();
679
680 if ( ! $this->jr_id=$acc_operation->insert_jrn() ) {
681 throw new Exception (_("Erreur de balance"),EXC_BALANCE);
682 }
683
684 $this->pj = $acc_operation->update_receipt();
685
686 /**
687 *
688 * if the given receipt number is equal to one computed then increment
689 */
690 if ($e_pj == $this->pj && noalyss_strlentrim($e_pj) != 0) {
691 $this->inc_seq_pj();
692 }
693 $this->db->exec_sql("update jrn set jr_internal=$1 where jr_grpt_id = $2" ,[$internal,$seq]);
694
695
696 /* update quant_sold */
697 $this->db->exec_sql('update quant_sold set qs_internal = $1
698 where j_id in (select j_id from jrnx where j_grpt=$2)'
699 , array($internal, $seq));
700
701 /* Save the attachment or generate doc */
702 if (isset($_FILES['pj'])) {
703 if (noalyss_strlentrim($_FILES['pj']['name']) != 0)
704 $this->db->save_receipt($seq);
705 else
706 /* Generate an invoice and save it into the database */
707 if (isset($_POST['gen_invoice'])) {
708 $file = $this->create_document($internal, $p_array);
709 $this->doc=HtmlInput::show_receipt_document($this->jr_id,h($file));
710 }
711 }
712 //----------------------------------------
713 // Save the payer
714 //----------------------------------------
715 if ($e_mp != 0) {
716 /**
717 * Date
718 */
719 $pay_date=($mp_date=="")?$e_date:$mp_date;
720
721 /* mp */
722 $mp = new Acc_Payment($this->db, $e_mp);
723 $mp->load();
724
725
726 /* jrnx */
727 $acseq = $this->db->get_next_seq('s_grpt');
728 $acjrn = new Acc_Ledger($this->db, $mp->get_parameter('ledger_target'));
729 $acinternal = $acjrn->compute_internal_code($acseq);
730
731 /*
732 * for the use of the card of the bank
733 */
734 if ( $acjrn->get_type()=='FIN') {
735 $acjrn=new Acc_Ledger_Fin($this->db, $mp->get_parameter('ledger_target'));
736 $acfiche=new Fiche($this->db,$acjrn->get_bank());
737 $fqcode=$acfiche->strAttribut(ATTR_DEF_QUICKCODE);
738 } else {
739 $fqcode = ${'e_mp_qcode_' . $e_mp};
740 $acfiche = new Fiche($this->db);
741 $acfiche->get_by_qcode($fqcode);
742 }
743
744 /* Insert paid by */
745 $acc_pay = new Acc_Operation($this->db);
746 $acc_pay->date = $pay_date;
747 /* get the account and explode if necessary */
748 $sposte = $acfiche->strAttribut(ATTR_DEF_ACCOUNT);
749 // if 2 accounts, take only the debit one for customer
750 if (strpos($sposte, ',') != 0) {
751 $array = explode(',', $sposte);
752 $poste_val = $array[0];
753 } else {
754 $poste_val = $sposte;
755 }
756 // Convert paid amount in EUR
757 $acompte_eur=bcdiv($acompte, $p_currency_rate);
758
759 $famount=bcsub($cust_amount,$acompte_eur);
760 $acc_pay->poste = $poste_val;
761 $acc_pay->qcode = $fqcode;
762 $acc_pay->amount = abs(round($famount, 2));
763 $acc_pay->desc = null;
764
765 $acc_pay->grpt = $acseq;
766 $acc_pay->jrn = $mp->get_parameter('ledger_target');
767 $acc_pay->periode = $tperiode;
768 $acc_pay->type = ($famount >= 0) ? 'd' : 'c';
769 $let_pay=$acc_pay->insert_jrnx();
770
771 /* Insert supplier */
772 $acc_pay = new Acc_Operation($this->db);
773 $acc_pay->date = $pay_date;
774 $acc_pay->poste = $poste;
775 $acc_pay->qcode = $e_client;
776 $acc_pay->amount = abs(round($famount, 2));
777 $acc_pay->desc = null;
778 $acc_pay->grpt = $acseq;
779 $acc_pay->jrn = $mp->get_parameter('ledger_target');
780 $acc_pay->periode = $tperiode;
781 $acc_pay->type = ($famount >= 0) ? 'c' : 'd';
782 $let_other = $acc_pay->insert_jrnx();
783
784 // insert into operation_currency customer
785 $operation_currency=new Operation_currency_SQL($this->db);
786 $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
787 $operation_currency->oc_vat_amount=0;
788 $operation_currency->oc_price_unit=0;
789 $operation_currency->j_id=$let_other;
790 $operation_currency->insert();
791
792 // insert into operation_currency bank
793 $operation_currency=new Operation_currency_SQL($this->db);
794 $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
795 $operation_currency->oc_vat_amount=0;
796 $operation_currency->oc_price_unit=0;
797 $operation_currency->j_id=$let_pay;
798 $operation_currency->insert();
799
800 // Add info for currency
801 $acc_pay->currency_id=$p_currency_code;
802 $acc_pay->currency_rate=$p_currency_rate;
803 $acc_pay->currency_rate_ref=$currency_rate_ref->get_rate();
804
805
806 /* insert into jrn */
807 $acc_pay->mt = $mt;
808 $acjrn->grpt_id = $acseq;
809 $acc_pay->desc = (!isset($e_comm_paiement) || noalyss_strlentrim($e_comm_paiement) == 0) ? $e_comm : $e_comm_paiement;
810 $mp_jr_id = $acc_pay->insert_jrn();
811 $acjrn->update_internal_code($acinternal);
812 // add an automatic PJ if ODS
813 if ($acjrn->get_type()=="ODS") {
814 $acc_pay->pj=$acjrn->guess_pj();
815 $acc_pay->update_receipt();
816 }
817 $r1 = $this->get_id($internal);
818 $r2 = $this->get_id($acinternal);
819
820 /*
821 * add lettering
822 */
823 $oletter = new Lettering($this->db);
824 $oletter->insert_couple($let_tiers, $let_other);
825
826
827 /* set the flag paid */
828 $Res = $this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1", array($r1));
829
830 /* Reconcialiation */
831 $rec = new Acc_Reconciliation($this->db);
832 $rec->set_jr_id($r1);
833 $rec->insert($r2);
834
835
836 /*
837 * save also into quant_fin
838 */
839
840 /* get ledger property */
841 $ledger = new Acc_Ledger_Fin($this->db, $acc_pay->jrn);
842 $prop = $ledger->get_propertie();
843
844 /* if ledger is FIN then insert into quant_fin */
845 if ($prop['jrn_def_type'] == 'FIN') {
846 $ledger->insert_quant_fin($acfiche->id, $mp_jr_id, $cust->id, bcmul($famount, 1),$let_other);
847 }
848 }
849 /*----------------------------------------------
850 * Save the note
851 ----------------------------------------------*/
852 if (isset($p_array['jrn_note_input']) && !empty($p_array['jrn_note_input'])) {
853 $acc_operation_note=Acc_Operation_Note::build_jrn_id(-1);
854 $acc_operation_note->setNote($p_array['jrn_note_input']);
855 $acc_operation_note->setOperation_id( $this->jr_id);
856 $acc_operation_note->save();
857 }
858 } catch (Exception $e) {
859 record_log($e);
860 $this->db->rollback();
861 throw $e;
862 }
863 $this->db->commit();
864
865 return $internal;
866 }
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
sql_string($p_string)
Fix the problem with the quote char for the database.
$op jr_id
inc_seq_pj()
increment the sequence for the pj
compute_internal_code($p_grpt)
compute the internal code of the saved operation and set the $this->jr_internal to the computed value
$row
!< database connextion
create_document($internal, $p_array)
create the invoice and saved it as attachment to the operation,
get_id($p_internal)
retrieve the jr_id thanks the internal code, do not change anything to the current object
static show_receipt_document($p_jr_id, $p_name="")
Returns HTML code for displaying a icon with a link to a receipt document from the ledger.
static insert_goods(&$p_cn, $p_array)
Insert into stock_goods from ACH and VEN.
$check_periode
const EXC_BALANCE
Definition constant.php:349
const ATTR_DEF_QUICKCODE
Definition constant.php:237
$_POST['ac']
Definition do.php:312

References $_POST, $acompte, $amount, $array, $check_periode, $e, $e_date, $fiche, $file, $g_parameter, $g_user, $i, $j_id, $ledger, $op, $oPeriode, $other_tax_amount, $p_array, $p_jrn, $poste, $prop, $r, $repo, $Res, Acc_Ledger\$row, $seq, $tot_amount, $value, _, ATTR_DEF_ACCOUNT, ATTR_DEF_QUICKCODE, Acc_Tva\build(), Acc_Operation_Note\build_jrn_id(), Acc_Ledger\check_periode(), Acc_Ledger\compute_internal_code(), Acc_Ledger\create_document(), db, EXC_BALANCE, Acc_Ledger\get_id(), h, Acc_Ledger\has_other_tax(), Acc_Ledger\inc_seq_pj(), Stock_Goods\insert_goods(), jr_id, noalyss_strlentrim(), record_log(), and sql_string().

+ Here is the call graph for this function:

◆ verify_operation()

Acc_Ledger_Sale::verify_operation ( $p_array)

verify that the data are correct before inserting or confirming

Parameters
anarray (usually $_POST)
Returns
String
Exceptions
Exceptionif an error occurs

Reimplemented from Acc_Ledger.

Definition at line 48 of file acc_ledger_sale.class.php.

48 {
49 global $g_parameter, $g_user;
50
51 if (is_array($p_array ) == false || empty($p_array))
52 throw new Exception ("Array empty");
53
54 extract($p_array, EXTR_SKIP);
55
56 /*
57 * Check needed value
58 */
59 check_parameter($p_array,'p_jrn,e_date,e_client');
60
61 /* check for a double reload */
62 if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1', array($mt)) != 0)
63 throw new Exception(_('Double Encodage'), 5);
64
65 /* check if we can write into this ledger */
66 if ($g_user->check_jrn($p_jrn) != 'W')
67 throw new Exception(_('Accès interdit'), 20);
68
69 /* check if there is a customer */
70 if (noalyss_strlentrim($e_client) == 0)
71 throw new Exception(_('Vous n\'avez pas donné de client'), 11);
72
73 /* check if the date is valid */
74 if (isDate($e_date) == null) {
75 throw new Exception(_('Date invalide'), 2);
76 }
77
78 $oPeriode = new Periode($this->db);
79 if ($this->check_periode() == true && isset($p_array['period'])) {
80 $tperiode = $period;
81 /* check that the datum is in the choosen periode */
82 $oPeriode->p_id = $period;
83 list ($min, $max) = $oPeriode->get_date_limit();
84
85 if (cmpDate($e_date, $min) < 0 ||
86 cmpDate($e_date, $max) > 0)
87 throw new Exception(_('Date et periode ne correspondent pas'), 6);
88 }
89 else {
90 $per = new Periode($this->db);
91 $tperiode = $per->find_periode($e_date);
92 }
93
94 /* check if the periode is closed */
95 if ($this->is_closed($tperiode) == 1) {
96 throw new Exception(_('Periode fermee'), 6);
97 }
98 /* check if we are using the strict mode */
99 if ($this->check_strict() == true) {
100 /* if we use the strict mode, we get the date of the last
101 operation */
102 $last_date = $this->get_last_date();
103 if ($last_date != null && cmpDate($e_date, $last_date) < 0)
104 throw new Exception(_('Vous utilisez le mode strict la dernière operation est date du ')
105 . $last_date . _(' vous ne pouvez pas encoder à une date antérieure'), 13);
106 }
107
108
109 $fiche = new Fiche($this->db);
110 $fiche->get_by_qcode($e_client);
111
112 if ($fiche->get_f_enable() == '0')
113 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée"),$e_client), 50);
114
115 if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
116 throw new Exception(_('La fiche ') . $e_client . _('n\'a pas de poste comptable'), 8);
117
118
119
120 /* get the account and explode if necessary */
121 $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
122 // if 2 accounts, take only the debit one for customer
123 if (strpos($sposte, ',') != 0) {
124 $array = explode(',', $sposte);
125 $poste_val = $array[0];
126 } else {
127 $poste_val = $sposte;
128 }
129 /* The account exists */
130
131 $poste = new Acc_Account_Ledger($this->db, $poste_val);
132
133 if ($poste->load() == false) {
134 throw new Exception(_('Pour la fiche ') . $e_client . _(' le poste comptable [') . $poste->id . _('] n\'existe pas'), 9);
135 }
136
137 /* Check if the card belong to the ledger */
138 $fiche = new Fiche($this->db);
139 $fiche->get_by_qcode($e_client, 'deb');
140 if ($fiche->belong_ledger($p_jrn) != 1)
141 throw new Exception(_('La fiche ') . $e_client . _('n\'est pas accessible à ce journal'), 10);
142
143 $nb = 0;
144
145 //----------------------------------------
146 // foreach item
147 //----------------------------------------
148 for ($i = 0; $i < $nb_item; $i++) {
149 if (! isset (${'e_march' . $i}) || noalyss_strlentrim(${'e_march' . $i}) == 0)
150 continue;
151 /* check if all card has a ATTR_DEF_ACCOUNT */
152 $fiche = new Fiche($this->db);
153 $fiche->get_by_qcode(${'e_march' . $i});
154 if ($fiche->get_f_enable() == '0')
155 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée"), ${'e_march' . $i}), 50);
156
157
158 /* check if amount are numeric and */
159 if (isNumber(${'e_march' . $i . '_price'}) == 0)
160 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un montant invalide [') . ${'e_march' . $i} . ']', 6);
161 if (isNumber(${'e_quant' . $i}) == 0)
162 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a une quantité invalide [') . ${'e_quant' . $i} . ']', 7);
163
164 if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
165 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'a pas de poste comptable'), 8);
166
167 // Check if the given tva id is valid
168 if ($g_parameter->MY_TVA_USE == 'Y') {
169 $tva_rate = Acc_Tva::build($this->db,${'e_march' . $i . '_tva_id'});
170 $tva_rate->load();
171 if ($tva_rate->tva_id === -1 )
172 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
173
174 $tva_rate->load();
175 /*
176 * check if the accounting for VAT are valid
177 */
178 $a_poste = explode(',', $tva_rate->tva_poste);
179
180 if (
181
182 $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1', array($a_poste[1])) == 0)
183 throw new Exception(_(" La TVA " . $tva_rate->tva_label . " utilise des postes comptables inexistants"));
184 }
185 // if 2 accounts, take only the credit one
186 /* The account exists */
187 $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
188
189 if (strpos($sposte, ',') != 0) {
190 $array = explode(',', $sposte);
191 $poste_val = $array[1];
192 } else {
193 $poste_val = $sposte;
194 }
195 $poste = new Acc_Account_Ledger($this->db, $poste_val);
196 if ($poste->load() == false) {
197 throw new Exception(_('Pour la fiche ') . ${'e_march' . $i} . _(' le poste comptable [') . $poste->id . _('n\'existe pas'), 9);
198 }
199 /* Check if the card belong to the ledger */
200 $fiche = new Fiche($this->db);
201 $fiche->get_by_qcode(${'e_march' . $i});
202 if ($fiche->belong_ledger($p_jrn, 'cred') != 1)
203 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'est pas accessible à ce journal'), 10);
204
205 if ( ${"e_quant".$i} != 0 && trim(${"e_quant".$i}) !="" ) {$nb++;}
206
207 }
208 if ($nb == 0)
209 throw new Exception(_('Il n\'y a aucune marchandise'), 12);
210 //------------------------------------------------------
211 // The "Paid By" check
212 //------------------------------------------------------
213
214 if ($e_mp != 0) {
215 $this->check_payment($e_mp, ${"e_mp_qcode_" . $e_mp});
216 // check for the currency , if we use a financial ledger and a card which is a bank account (with his own
217 // ledger , then the currency of the operation must be the same
218 $this->check_currency(${"e_mp_qcode_" . $e_mp},$p_currency_code);
219 }
220
221
222
223
224 //
225 // Check payment date
226 if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == null) {
227 throw new Exception(_('Date de paiement invalide'),13);
228
229 }
230
231 // check that MP is in a not closed and exists
232 if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == $mp_date ) {
233 $periode=new Periode($this->cn);
234 $periode->find_periode($mp_date);
235 $periode->set_ledger($this->id);
236 if ( $periode->is_closed() ) {
237 throw new Exception(_("Période fermée")." $mp_date ");
238 }
239
240 }
241 // check limit date
242 if ( isset ($e_ech) && trim ($e_ech)!="" && isDate($e_ech) == null )
243 {
244 throw new Exception(_('Date échéance invalide'),14);
245
246 }
247 // Check currency_rate if valid
248 if ( isNumber($p_currency_rate) == 0 || $p_currency_rate <=0 ) {
249 throw new Exception(_('Taux devise invalide'),15);
250 }
251 $this->check_currency_setting($p_currency_code);
252 }
isNumber($p_int)
isDate($p_date)
cmpDate($p_date, $p_date_oth)
Compare 2 dates.
catch(Exception $e) $tva_rate
for($i=0; $i< count($plan); $i++)( $j==0) $a_poste
$nb
!< type of the ledger ACH ODS FIN VEN or GL
check_currency($p_qcode_payment, $p_currency_id)
When we write a record for the payment at the same time as a sale or a purchase, to have a bank saldo...
is_closed($p_periode)
check if the current ledger is closed
check_payment($e_mp, $e_mp_qcode)
check if the payment method is valid
get_last_date()
get the date of the last operation
check_strict()
Check if a Dossier is using the strict mode or not.
check_currency_setting($p_currency_code)
Check that the currency code does exist and the setting of the folder is correct.
check_parameter($p_array, $p_needed)
Check that all the index are in the array, used by function to check if the array contains the needed...

References $a_poste, $array, $e_date, $fiche, $g_parameter, $g_user, $i, $max, $min, Acc_Ledger\$nb, $oPeriode, $p_array, $p_jrn, $per, $periode, $poste, $tva_rate, _, ATTR_DEF_ACCOUNT, Acc_Tva\build(), Acc_Ledger\check_currency(), Acc_Ledger\check_currency_setting(), check_parameter(), Acc_Ledger\check_payment(), Acc_Ledger\check_periode(), Acc_Ledger\check_strict(), cmpDate(), cn, db, Acc_Ledger\get_last_date(), Acc_Ledger\is_closed(), isDate(), isNumber(), and noalyss_strlentrim().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: