Commit cce546c1 authored by Ifaliana Arimanana's avatar Ifaliana Arimanana
Browse files

payement lila

parent 467a4935
......@@ -96,6 +96,7 @@ class Form {
"tpls.forms.cplx.openDynform" => "Tableau ou liste de réponse (Open Dynamic Form)",
"tpls.forms.cplx.multitextvalidation" => "Text : petit text court Configurable",
"tpls.forms.cplx.multiRadio" => "Bouton Radio : Multiple options et Choix unique",
"tpls.forms.cplx.typeEtDroitAdhesion" => "Montant par type",
"tpls.forms.cplx.multiCheckboxPlus" => "Case à cocher : Multiple options et Multiple Choix "
];
......
<style type="text/css">
select option, select optgroup{
font-size: 12pt !important;
padding-top: 3em !important;
}
.form-control{
padding: .5em !important;
}
</style>
<?php if($answer){ ?>
<div class="col-md-6">
<?php
$types = array();
if(!function_exists("get_types")){
function get_types(&$types, $label){
$exist = false;
foreach ($types as $k => &$v) {
if($v==$label){
$exist = true;
}
}
if(!$exist){
array_push($types, "$label");
}
}
}
# Initialize parameters data
$paramsData = [
"types" => [
"type0" => [
"type" => "Acteurs producteurs",
"label" => "",
"droit" => 0
],
"type1" => [
"type" => "Bénéficiaires",
"label" => "",
"droit" => 0
]
]
];
# Set parameters data
if( isset($form["params"][$kunik]["types"]) )
$paramsData["types"] = $form["params"][$kunik]["types"];
// remove the to test directily (dev) "draft" => ["$exists" => false ]]
$theAnswers = PHDB::find("answers", array("user"=>Yii::app()->session["userId"], "form"=>$parentForm["_id"]->{'$id'}, "draft" => ['$exists' => false ]));
$editParamsBtn = ($canEditForm) ? "<a href='javascript:;'
data-id='".$form["_id"]."'
data-collection='".Form::COLLECTION."'
data-path='params.".$kunik."'
class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'>
<i class='fa fa-cog'></i>
</a>" : "";
?>
<h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>">
<?php echo $label.$editQuestionBtn." ".$editParamsBtn?>
</h4>
<?php echo $info ?>
<?php
$selected_type = (isset($answer["answers"][$form["id"]]["type"]))?$answer["answers"][$form["id"]]["type"]:"";
//$p = PHDB::findOne("payments", array('user' => $_SESSION["userId"], 'source.form' => $form["id"]));
?>
<br>
<div class="form-group">
<select id="<?= $key ?>" data-form="<?= $form["id"]?>" class="form-control saveOneByOne">
<option></option>
<?php foreach ($paramsData["types"] as $tkey => $tvalue) {
$l = (isset($tvalue["label"])?$tvalue["label"]:"");
echo '<option value="'.base64_encode(json_encode($tvalue)).'">'.$l.' ( <b> '.$tvalue["droit"].' € </b> )</option>';
} ?>
</select>
<?php
// echo ($canEditForm)?"<div class='input-group-btn'>".$editParamsCheckbox."</div>":""; ?>
</div>
<br>
<hr>
<div class="form-group">
<b>Montant à payer : </b>
<span id="total">0 </span>
</div>
<hr>
<?php if(isset($answer["answers"]["isPaid"])){ ?>
<div class="form-group">
<b>Statut : </b>
<span class="label label-success"> PAYE </span>
</div>
<?php } ?>
<div class="form-group">
<a id="btn-payement" disabled class="btn btn-success btn-lg" style="text-decoration : none;">
Proceder au Payement
</a>
<?php if(isset($answer["answers"]["isPaid"])){ ?>
<a id="btn-facturation" class="btn btn-success btn-lg" href="<?= Yii::app()->baseUrl; ?>/survey/payment/invoice?id=<?= $this->costum['contextId'] ?>&slug=<?= $this->costum['slug']; ?>&user=<?= $_SESSION['userId']; ?>&form=<?= $answer["form"]; ?>" target="_blank" style="text-decoration : none;">
Télécharger Facture
</a>
<?php } ?>
<span id="load-payment"></span>
</div>
</div>
<script type="text/javascript">
sectionDyf.<?php echo $kunik ?>ParamsData = <?php echo json_encode( $paramsData ); ?>;
var typeAssocie = <?php echo json_encode( $types ); ?>;
var isPaid = <?php echo json_encode(isset($answer["answers"]["isPaid"])); ?>;
// Initialize from answers
$("#<?=$key?>").val("<?= $selected_type ?>");
$("#<?=$key?>").val("<?= $selected_type ?>");
if(isPaid){
$("#btn-payement").attr("disabled", true);
}else{
$("#btn-payement").attr("disabled", false);
}
if($("#<?=$key?>").val()!=""){
const st = JSON.parse(atob($("#<?= $key ?>").val()));
$("#total").text(st.droit+"");
}
$(document).ready(function(){
let kunik = "<?= $kunik ?>";
let droit = {};
let evaluations = "<?php echo ""; //json_encode( $myEvaluation ); ?>";
let evaluationtypes = "<?php echo ""; // json_encode( $paramsData["types"] ); ?>";
let options = [];
sectionDyf.<?php echo $kunik ?>ParamsSelect = {
"jsonSchema" : {
"title" : "Paramétrage du <?php echo $kunik ?>",
"description" : "",
"icon" : "fa-cog",
"properties" : {
types : {
inputType : "lists",
label : "Type d'associé",
entries: {
label: {
label:"Type :",
type:"textarea",
class:"col-md-6"
},
droit: {
label:"Droit :",
type:"text",
class:"col-md-2",
placeholder:"En €"
}
},
}
},
save : function (data) {
tplCtx.value = {};
$.each( sectionDyf.<?php echo $kunik ?>ParamsSelect.jsonSchema.properties , function(k,val) {
if(k=="types"){
let types = {};
$.each(data.types, function(index, va){
let tpa = {type: va.type,label: va.label, droit: va.droit};
types["type"+index] = tpa;
});
tplCtx.value[k] = types;
}else{
tplCtx.value[k] = $("#"+k).val();
}
mylog.log("value",'.'+k+val.inputType,tplCtx.value[k]);
});
mylog.log("save tplCtx",tplCtx);
if(typeof tplCtx.value == undefined)
toastr.error('value cannot be empty!');
else {
dataHelper.path2Value( tplCtx, function(params) {
$("#ajax-modal").html("<div class='text-center'><i class='fa fa-spin fa-spinner'></i></div>");
location.reload();
} );
}
}
}
};
$("input[data-entry=type]").off().on("focus", function() {
alert( "Handler for .focus() called." );
});
$("#<?= $key ?>, #nbPart").off().on("change", function(){
const nbPartValue = (!isNaN($("#nbPart").val()) && $("#nbPart").val()!=0)?$("#nbPart").val():1;
const st = ($("#<?= $key ?>").val()!="")?JSON.parse(atob($("#<?= $key ?>").val())):0;
$("#total").text(st.droit+" €");
if(st.droit*$("#nbPart").val()==0){
$("#btn-payement").attr("disabled", true);
}else{
$("#btn-payement").text("Proceder au paiement de "+st.droit+" €");
$("#btn-payement").attr("disabled", false);
}
$(this).blur();
});
$("#btn-payement").off().on("click", function(){
// Save all before pay
$(".saveOneByOne").blur();
if($(".saveOneByOne").val()!=""){
coInterface.showLoader("#load-payment");
const st = JSON.parse(atob($("#<?= $key ?>").val()));
var paymentData = {
"amount" :{
"currency" : "EUR",
"value" : ""+parseFloat(st.droit).toFixed(2)+""
},
"description": "Droit d'associé en tant que à titre de "+st.label,
"page": window.location.href,
"form": "<?=$answer["form"]?>",
"nombre": 1
}
$.ajax({
url: '<?= Yii::app()->baseUrl; ?>/survey/payment/pay',
type: 'POST',
data: paymentData,
dataType: "json"
}).done(function(data){
location = data.url;
}).fail(function(xhr,textStatus,errorThrown,data){
toastr.error("Une erreur s'est produite, veuillez signaler ce problème à notre administrateur");
});
}else{
toastr.warning("Veuillez remplir toutes avant de payer votre droit d'associé")
}
});
$("#btn-facturation").off().on("click", function(){
});
//adds a line into answer
$(".add<?php echo $kunik ?>").off().on("click",function() {
tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection");
tplCtx.path = $(this).data("path")+((notNull(<?php echo $kunik ?>Data) ? <?php echo $kunik ?>Data.length : "0"));
dyFObj.openForm( sectionDyf.<?php echo $kunik ?> );
});
$(".edit<?php echo $kunik ?>").off().on("click",function() {
tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection");
tplCtx.path = $(this).data("path");
dyFObj.openForm( sectionDyf.<?php echo $kunik ?>,null, <?php echo $kunik ?>Data[$(this).data("key")]);
});
$(".edit<?php echo $kunik ?>Params").off().on("click",function() {
tplCtx.id = $(this).data("id");
tplCtx.collection = $(this).data("collection");
tplCtx.path = $(this).data("path");
//if no params config on the element.costum.form.params.<?php echo $kunik ?>
//then we load default values available in forms.inputs.<?php echo $kunik ?>xxx.params
//mylog.log(".editParams",sectionDyf.<?php echo $kunik ?>Params,calData);
dyFObj.openForm( sectionDyf.<?php echo $kunik ?>ParamsSelect,null, sectionDyf.<?php echo $kunik ?>ParamsData);
});
});
</script>
<?php } else {
//echo "<h4 class='text-red'>evaluation works with existing answers</h4>";
} ?>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment