From fec01ee1bcd6cbe6d2b327cc9c2a62454b69ea44 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 20 Jan 2022 22:59:33 +0100 Subject: [PATCH] Added billing fields to address --- Layout/default/Address/Form.php | 145 +++++++++++++++++++++- application/Address/AddressController.php | 43 ++++++- application/Address/AddressModel.php | 2 - scripts/import_customers_from_ivt.php | 2 +- 4 files changed, 184 insertions(+), 8 deletions(-) diff --git a/Layout/default/Address/Form.php b/Layout/default/Address/Form.php index 9e1b4eb11..36e0b91cd 100644 --- a/Layout/default/Address/Form.php +++ b/Layout/default/Address/Form.php @@ -22,9 +22,9 @@
-

id) ? "Person/Firma bearbeiten" : "Neue Person/Firma"?>

+

id) ? "Person/Firma bearbeiten" : "Neue Person/Firma"?>

-
"> + ">
@@ -131,6 +131,24 @@
+

Einwilligungen

+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
@@ -158,7 +176,72 @@
-

Zusatzdaten

+ +

Verrechnungsdaten

+
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ + +
+
+ +
+ +
+ +
+
+ + +
+
+ + +

Zusatzdaten

@@ -181,10 +264,12 @@
+ +
- +
@@ -204,6 +289,58 @@ placeholder: "" }); $("#addresstypes").select2(); + + + + + function validateIban(iban) { + if(!iban) { + return false; + } + iban = iban.toUpperCase().replace(/\s+/, ''); + //check format + var m; + + if(!iban.match(/^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$/)) { + return false; + } + + var cc = iban.substr(0, 2); + var check = parseInt(iban.substr(2, 2)); + var account = iban.substr(4); + + var searchRange = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(''); + //var replaceRange = []; + var checkStr = account + cc + "00"; + for(var i = 0; i <= 25; i++) { + checkStr = checkStr.replace(searchRange[i], i + 10); + }; + // make checksum + var checksum = parseInt(checkStr.substr(0,1)); + for(pos = 1; pos < checkStr.length; pos++) { + checksum *= 10; + checksum += parseInt(checkStr.substr(pos, 1)); + checksum %= 97; + } + + if(98 - checksum == check) { + return true; + } else { + return false; + } + } + + $('#addressForm').submit(function(e) { + $("#error").hide(); + if($('#billing_type').val() == "sepa" && !validateIban($("#bank_account_iban").val())) { + $("#error").show(); + console.log("nope"); + e.preventDefault(); + return false; + } + return true; + }); + \ No newline at end of file diff --git a/application/Address/AddressController.php b/application/Address/AddressController.php index 82147aecc..cb56d36a0 100644 --- a/application/Address/AddressController.php +++ b/application/Address/AddressController.php @@ -104,7 +104,7 @@ class AddressController extends mfBaseController { protected function saveAction() { $r = $this->request; $id = $r->id; - //var_dump($r); + //var_dump($r);exit; if(is_numeric($id) && $id > 0) { $mode = "edit"; $address = new Address($id); @@ -132,6 +132,47 @@ class AddressController extends mfBaseController { $data['mobile'] = $r->mobile; $data['email'] = $r->email; $data['note'] = $r->note; + $data['uid'] = $r->uid; + + + // billing data + // validate sepa + if(!$r->billing_type) { + $this->layout()->setFlash("Ungültige Verrechnungsart."); + $this->layout()->set("order", $r); + return $this->add(); + } + + if($r->billing_type == "sepa") { + foreach(['bank', 'owner', 'iban', 'bic'] as $required) { + if(!$r->{"bank_account_$required"}) { + $this->layout()->setFlash("Bitte Bankdaten für SEPA ausfüllen."); + $this->layout()->set("address", $r); + return $this->add(); + } + } + } + + if($r->billing_type == "sepa") { + $data['billing_type'] = "sepa"; + } else { + $data['billing_type'] = "invoice"; + } + + if($r->billing_delivery == "paper") { + $data['billing_delivery'] = "paper"; + } else { + $data['billing_delivery'] = "email"; + } + + + $data['bank_account_bank'] = $r->bank_account_bank; + $data['bank_account_owner'] = $r->bank_account_owner; + $data['bank_account_iban'] = $r->bank_account_iban; + $data['bank_account_bic'] = $r->bank_account_bic; + $data['allow_contact'] = ($r->allow_contact) ? 1 : 0; + $data['allow_spin'] = ($r->allow_spin) ? 1 : 0; + $data['edit_by'] = 1; diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php index 9bfec03d1..738a6e718 100644 --- a/application/Address/AddressModel.php +++ b/application/Address/AddressModel.php @@ -25,8 +25,6 @@ class AddressModel { public $allow_contact; public $allow_spin; - - public $note = null; public $create_by = null; diff --git a/scripts/import_customers_from_ivt.php b/scripts/import_customers_from_ivt.php index 5a5ba6734..4bd4373ae 100644 --- a/scripts/import_customers_from_ivt.php +++ b/scripts/import_customers_from_ivt.php @@ -24,7 +24,7 @@ foreach(IvtCustomerModel::getAll() as $cust) { if(!$cust->id) { continue; } - foreach(['deleted', 'deletet', 'deleded', 'delete'] as $word) { + foreach(['deleted', 'deletet', 'deleded', 'delete', 'deledet'] as $word) { if(strtolower(trim($cust->company)) == $word || strtolower(trim($cust->surname)) == $word || strtolower(trim($cust->firstname)) == $word) { continue 2; }