@@ -76,27 +76,28 @@ public function __construct($db, $user, $type)
76
76
}
77
77
78
78
/**
79
- * Create
79
+ * Create a reject
80
80
*
81
81
* @param User $user User object
82
82
* @param int $id Id
83
83
* @param string $motif Motif
84
- * @param int $date_rejet Date rejet
84
+ * @param int $date_rejet Date reject
85
85
* @param int $bonid Bon id
86
- * @param int $facturation Facturation
87
- * @return void
86
+ * @param int $facturation 1=Bill the reject
87
+ * @return int Return >=0 if OK, <0 if KO
88
88
*/
89
89
public function create ($ user , $ id , $ motif , $ date_rejet , $ bonid , $ facturation = 0 )
90
90
{
91
- global $ langs, $ conf ;
91
+ global $ langs ;
92
92
93
93
$ error = 0 ;
94
94
$ this ->id = $ id ;
95
95
$ this ->bon_id = $ bonid ;
96
96
$ now = dol_now ();
97
97
98
- dol_syslog ("RejetPrelevement::Create id $ id " );
99
- $ bankaccount = ($ this ->type == 'bank-transfer ' ? $ conf ->global ->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $ conf ->global ->PRELEVEMENT_ID_BANKACCOUNT );
98
+ dol_syslog ("RejetPrelevement::Create id " .$ id );
99
+
100
+ $ bankaccount = ($ this ->type == 'bank-transfer ' ? getDolGlobalString ('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT ' ) : getDolGlobalString ('PRELEVEMENT_ID_BANKACCOUNT ' ));
100
101
$ facs = $ this ->getListInvoices (1 );
101
102
102
103
require_once DOL_DOCUMENT_ROOT .'/compta/prelevement/class/ligneprelevement.class.php ' ;
@@ -152,17 +153,16 @@ public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0
152
153
153
154
$ fac ->fetch ($ facs [$ i ][0 ]);
154
155
155
- // Make a negative payment
156
- //$pai = new Paiement($this->db);
156
+ $ amountrejected = $ facs [$ i ][1 ];
157
157
158
+ // Make a negative payment
159
+ // Amount must be an array (id of invoice -> amount)
158
160
$ pai ->amounts = array ();
159
161
160
- /*
161
- * We replace the comma with a point otherwise some
162
- * PHP installs sends only the part integer negative
163
- */
162
+ //var_dump($this->type);exit;
163
+
164
+ $ pai ->amounts [$ facs [$ i ][0 ]] = price2num ($ amountrejected * -1 ); // The payment must be negative because it is a refund
164
165
165
- $ pai ->amounts [$ facs [$ i ][0 ]] = price2num ($ facs [$ i ][1 ] * ($ this ->type == 'bank-transfer ' ? 1 : -1 ));
166
166
$ pai ->datepaye = $ date_rejet ;
167
167
$ pai ->paiementid = 3 ; // type of payment: withdrawal
168
168
$ pai ->num_paiement = $ fac ->ref ;
@@ -175,7 +175,13 @@ public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0
175
175
$ error ++;
176
176
dol_syslog ("RejetPrelevement::Create Error creation payment invoice " .$ facs [$ i ][0 ]);
177
177
} else {
178
- $ result = $ pai ->addPaymentToBank ($ user , 'payment ' , '(InvoiceRefused) ' , $ bankaccount , '' , '' );
178
+ // We record entry into bank
179
+ $ mode = 'payment ' ;
180
+ if ($ this ->type == 'bank-transfer ' ) {
181
+ $ mode = 'payment_supplier ' ;
182
+ }
183
+
184
+ $ result = $ pai ->addPaymentToBank ($ user , $ mode , '(InvoiceRefused) ' , $ bankaccount , '' , '' );
179
185
if ($ result < 0 ) {
180
186
dol_syslog ("RejetPrelevement::Create AddPaymentToBan Error " );
181
187
$ error ++;
@@ -200,9 +206,13 @@ public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0
200
206
if ($ error == 0 ) {
201
207
dol_syslog ("RejetPrelevement::Create Commit " );
202
208
$ this ->db ->commit ();
209
+
210
+ return 1 ;
203
211
} else {
204
212
dol_syslog ("RejetPrelevement::Create Rollback " );
205
213
$ this ->db ->rollback ();
214
+
215
+ return -1 ;
206
216
}
207
217
}
208
218
0 commit comments