wpdb->insert('cdf_Credit', array( 'type_credit' => $data['loan_type'], 'sel_credit' => $data['sub_loan_type'], 'capital' => $data['selected_capital'], 'duree' => $data['selected_months'], 'cout_total' => $data['hidden_cout_total_value'], 'mensualite' => $data['hidden_montant_total_value'], 'taux_nominal_annuel' => $data['hidden_taeg_value'], 'rgpd' => 'oui', 'create_date' => (new \DateTime())->format('Y-m-d H:i:s') )); $current_credit_id = $this->wpdb->insert_id; $token = $this->generateToken($current_credit_id); $currentCredit = $this->getCredit($token); /* if($currentCredit->type_credit != 'pat') return $token; else $this->save_step_1_pat($data); */ return $token; } catch (\Exception $e) { die($e->getMessage()); } } public function save_step_1_all($data) { if(isset($data['email']) && strpos($data['email'], '@example.com') !== false) { return false; // Rejeter la demande si l'adresse email contient @example.com } $currentCredit = $this->getCredit($data['credit-direct-token']); if (!is_object($currentCredit)) { return false; } $borrower = $this->getBorrower($currentCredit); $borrowerTableName = 'cdf_Emprunteur'; $borrowerData = [ 'nom' => $data['lastname'], 'prenom' => $data['firstname'], 'telephone' => $data['phone'], 'email' => $data['email'], 'FK_agence' => $data['agency'], 'FK_demande_creditdirect' => $currentCredit->idCredit ]; if (is_object($borrower)) { $this->wpdb->update($borrowerTableName, $borrowerData, [ 'idemprunteur' => $borrower->idemprunteur ]); } else { $this->wpdb->insert($borrowerTableName, $borrowerData); } /** * Re-get the current credit to hydrate it */ $currentCredit = $this->getCredit($data['credit-direct-token']); $this->update_emprunteur($data, $currentCredit); $this->save_autre_credit_emprunteur($data, $currentCredit); if (array_key_exists('hascoborrower', $data) && $data['hascoborrower'] === '1') { $this->insert_co_emprunteur($data, $currentCredit); $this->save_autre_credit_co_emprunteur($data, $currentCredit); } $this->wpdb->update( 'cdf_Credit', array( 'last_update_date' => (new \DateTime())->format('Y-m-d H:i:s'), 'last_step' => '4' ), array('idCredit' => $this->currentCredit->idCredit) ); } public function save_one_step($data) { $email_demande = $data['email']; if(strpos($email_demande, '@example.com') !== false) { return false; // Rejeter la demande si l'adresse email contient @example.com } $currentCredit = $this->getCredit($data['credit-direct-token']); $included_hypo_credits = ['am','amr','cied','frais_notaire','cdp']; if (!is_object($currentCredit)) { return false; } /* if($this->is_webdev_user()) { echo '
';
            print_r($data);
            echo '
'; die(); } */ /* echo '
';
        print_r($data);
        echo '
'; die(); */ $ddn = null; if (!empty($data['birthdate'])) { $ddn = \DateTime::createFromFormat('d/m/Y', $data['birthdate']); if ($ddn) { $ddn = $ddn->format('Y-m-d'); } } // print_r($ddn); $independent_since = \DateTime::createFromFormat('d/m/Y', $data['independent_since']); if($independent_since) { $independent_since = $independent_since->format('Y-m-d'); } else { $independent_since = ''; } $borrower = $this->getBorrower($currentCredit); $borrowerTableName = 'cdf_Emprunteur'; $borrowerData = [ 'nom' => $data['lastname'], 'prenom' => $data['firstname'], 'telephone' => $data['phone'], 'email' => $data['email'], 'date_naissance' => $ddn ?: '', 'nationalité' => $data['nationality'], 'adresse' => $data['address'], 'code_postal' => $data['zip'], 'localite' => $data['city'], 'pays' => $data['country'], 'contract_type' => $data['contract_type'], 'independent_since' => $independent_since, 'FK_profession' => $data['job'], 'FK_etat_civil' => $data['civilstatus'], 'salaire' => $data['salary'], 'annual_taxable_income' => isset($data['annual_taxable_income']) ? $data['annual_taxable_income'] : null, 'FK_demande_creditdirect' => $currentCredit->idCredit, ]; /* if($this->is_webdev_user()) { echo '
';
            print_r($borrowerData);
            echo '
'; die(); } */ if (is_object($borrower)) { $this->wpdb->update($borrowerTableName, $borrowerData, [ 'idemprunteur' => $borrower->idemprunteur ]); } else { $this->wpdb->insert($borrowerTableName, $borrowerData); } if(!empty($data['comment'])) { $this->wpdb->update( 'cdf_Credit', array('commentaire' => $data['comment']), array('idCredit' => $currentCredit->idCredit) ); } if (array_key_exists('hascoborrower', $data) && $data['hascoborrower'] === '1') { $this->insert_co_emprunteur_one_step($data); } if (in_array($currentCredit->type_credit, $included_hypo_credits)) { $this->save_FK_credit_hypothecaire($currentCredit,$data); } if ( $currentCredit->type_credit == 'fin_neuve' || $currentCredit->type_credit == 'fin_occ_m3a' || $currentCredit->type_credit == 'fin_occ_p3a' ) { $this->save_FK_credit_auto($currentCredit,$data); } $this->save_to_credits_listing($currentCredit); } public function insert_co_emprunteur_one_step($data) { $currentCredit = $this->getCredit($data['credit-direct-token']); $borrower = $this->getBorrower($currentCredit); $this->wpdb->insert('cdf_Emprunteur',array( 'nom' => $data['colastname'], 'prenom' => $data['cofirstname'], 'date_naissance' => $data['cobirthdate'], 'nationalité' => $data['conationality'], 'adresse' => $data['coaddress'], 'code_postal' => $data['cozip'], 'localite' => $data['cocity'], 'pays' => $data['cocountry'], 'contract_type' => $data['cocontract_type'], 'independent_since' => isset($data['coindependent_since']) ? $data['coindependent_since'] : null, 'salaire' => $data['cosalary'], 'annual_taxable_income' => isset($data['coannual_taxable_income']) ? $data['coannual_taxable_income'] : null, 'parent_emprunteur' => $borrower->idemprunteur, 'FK_demande_creditdirect' => $currentCredit->idCredit, 'FK_etat_civil' => $data['cocivilstatus'], 'FK_profession' => $data['cojob'] )); } public function save_FK_credit_hypothecaire($currentCredit,$data) { $included_hypo_credits = ['am','amr','cied','frais_notaire','cdp']; if (in_array($currentCredit->type_credit, $included_hypo_credits)) { $optionsTableName = 'cdf_Options_credit_hypotecaire'; $optionsData = [ 'type_credit' => $data['estateloantype'], 'prix_achat' => $data['estatebuyingprice'], 'fonds_propre' => $data['estateequity'], 'compromis_signe' => $data['estatecompromise'], 'montant_a_emprunter' => $data['batiment_emprunt'], 'duree' => $data['batiment_duree'], ]; /** * job,contract_type,salary */ if (!is_null($currentCredit->FK_credit_hypothecaire)) { $this->wpdb->insert($optionsTableName, $optionsData, [ 'FK_credit_hypothecaire' => $currentCredit->FK_credit_hypothecaire ]); } else { $this->wpdb->insert($optionsTableName, $optionsData); $optionId = $this->wpdb->insert_id; $this->wpdb->update( 'cdf_Credit', array('FK_credit_hypothecaire' => $optionId), array('idCredit' => $currentCredit->idCredit) ); } $currentCredit = $this->getCredit($data['credit-direct-token']); /* echo '
';
            print_r($currentCredit);
            echo '
'; die(); */ } return $currentCredit; } public function save_FK_credit_auto($currentCredit,$data) { if ( $currentCredit->type_credit == 'fin_neuve' || $currentCredit->type_credit == 'fin_occ_m3a' || $currentCredit->type_credit == 'fin_occ_p3a' ) { $optionsTableName = 'cdf_Options_credit_auto'; $optionsData = [ 'marque' => $data['marque'], 'date_immatriculation' => $data['vehicleregistrationdate'], 'nom_vendeur' => $data['sellername'], 'adresse_vendeur' => $data['selleraddress'], 'prix_vehicule' => $data['vehicleprice'], 'montant_accompte' => $data['vehicule_accompte'], 'montant_reprise' => $data['vehicule_reprise'], 'montant_emprunt' => $data['vehicule_emprunt'], 'duree' => $data['vehicule_duree'] ]; if (!is_null($currentCredit->FK_credit_auto)) { $this->wpdb->update($optionsTableName, $optionsData, [ 'idOptions_credit_auto' => $currentCredit->FK_credit_auto ]); } else { $this->wpdb->insert($optionsTableName, $optionsData); $optionId = $this->wpdb->insert_id; $this->wpdb->update( 'cdf_Credit', array('FK_credit_auto' => $optionId), array('idCredit' => $currentCredit->idCredit) ); } /* $currentCredit = $this->getCredit($data['credit-direct-token']); */ } /* return $currentCredit; */ } }