-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditLoan.php
137 lines (136 loc) · 7.07 KB
/
editLoan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
session_start();
require_once('config.php');
require_once('autoload.php');
Helper_Access::rejectIfLogout();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script type="text/javascript" src="jquery-1.6.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#customer_id").blur(function(){
if($(this).val() == "") {
$("#customer_name").text("Aucune référence client entrée");
} else {
$("#customer_name").html("<img src=\"media/loading.gif\" alt=\"Chargement...\" />");
$.ajax({
type: "POST",
url: "loanAjax.php",
data: "action=search&type=customer&id="+$(this).val(),
success: function(msg) {
$("#customer_name").text(msg);
}
})
}
});
$("#lastline").live('focus',function() {
$(this).removeAttr("id");
$(this).append("<td><span class=\"article_delete\" style=\"cursor: pointer\"><img src=\"media/delete.png\" alt=\"Supprimer\" /></span></td>");
$("#table_body").append("\n\
<tr id=\"lastline\" class=\"table_line\">\n\
<td><input type=\"text\" name=\"article_id[]\" size=\"5\" class=\"article_id\" /></td>\n\
<td><input type=\"text\" class=\"article_name\" size=\"50\" disabled=\"disabled\" /></td>\n\
<td><input type=\"text\" name=\"article_qty[]\" size=\"2\" value=\"1\" /></td>\n\
<td><input type=\"checkbox\" name=\"article_date[]\" class=\"article_date\" /><input type=\"text\" name=\"article_date_begin[]\" class=\"article_date_begin\" size=\"10\" disabled=\"disabled\" /> - <input type=\"text\" name=\"article_date_end[]\" class=\"article_date_end\" size=\"10\" disabled=\"disabled\" /></td>\n\
</tr>");
});
$(".article_id").live('blur',function(){
var id = $(".article_id").index(this);
if($(this).val() != "") {
$($(".article_name")[id]).attr("value", "Recherche de l'article...");
$.ajax({
type: "POST",
url: "loanAjax.php",
data: "action=search&type=article&id="+$(this).val(),
success: function(msg) {
$($(".article_name")[id]).val(msg);
}
})
} else {
$($(".article_name")[id]).val("");
}
});
$(".article_date").live('change',function(){
var id = $(".article_date").index(this);
if($(this).attr("checked")) {
$($(".article_date_begin")[id]).removeAttr("disabled");
$($(".article_date_end")[id]).removeAttr("disabled");
} else {
$($(".article_date_begin")[id]).attr("disabled","disabled");
$($(".article_date_end")[id]).attr("disabled","disabled");
}
});
})
</script>
</head>
<?php if(isset($_GET['id'])): ?>
<?php else:
if(isset($_POST['send'])):
$loan = new Model_Loan();
$loan->setCustomer($_POST['customer']);
$loan->setReason($_POST['reason']);
$loan->setBegindate(Helper_Date::humanToTimestamp($_POST['date_begin']));
$loan->setEnddate(Helper_Date::humanToTimestamp($_POST['date_end']));
$loan->save();
foreach($_POST['article_id'] as $entry_id=>$article_id) {
$article = new Model_Loan_Article();
$article->setLoan($loan->getId());
$article->setArticle($article_id);
$qty = ($_POST['article_qty'][$entry_id] > 0) ? $_POST['article_qty'][$entry_id] : 1;
$article->setQuantity($qty);
if(isset($_POST['article_date'][$entry_id])) {
$article->setBegindate(Helper_Date::humanToTimestamp($_POST['article_date_begin'][$entry_id]));
$article->setEnddate(Helper_Date::humanToTimestamp($_POST['article_date_end'][$entry_id]));
}
$article->save();
}
else:
?>
<body>
<?php include_once 'search.php';?>
<script type="text/javascript">
$(document).ready(function() {
$(".article_delete").live('click',function(){
var id = $(".article_delete").index(this);
$($(".table_line")[id]).hide("200",function() {
$($(".table_line")[id]).remove();
});
});
})
</script>
<form method="POST" action="editLoan.php">
<table>
<tr><td>Référence client</td><td><input type="text" name="customer" size="6" id="customer_id" /> - <span id="customer_name">Aucune référence client entrée</span></td></tr>
<tr><td>Période</td><td>du <input type="text" name="date_begin" size="10" /> au <input type="text" name="date_end" size="10" /></td></tr>
<tr><td>Motif du prêt</td><td><input type="text" name="reason" size="100" /></td></tr>
<tr>
<td colspan="2">
<table>
<thead>
<td>Référence</td>
<td>Dénomination</td>
<td>Qté</td>
<td>Période (optionnel)</td>
</thead>
<tbody id="table_body">
<tr id="lastline" class="table_line">
<td><input type="text" name="article_id[]" size="5" class="article_id" /></td>
<td><input type="text" class="article_name" size="50" disabled="disabled" /></td>
<td><input type="text" name="article_qty[]" size="2" value="1" /></td>
<td><input type="checkbox" name="article_date[]" class="article_date" /><input type="text" name="article_date_begin[]" class="article_date_begin" size="10" disabled="disabled" /> - <input type="text" name="article_date_end[]" class="article_date_end" size="10" disabled="disabled" /></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr><td><input type="submit" name="send" value="Ajouter" /></td></tr>
</table>
</form>
</body>
<?php endif;
endif; ?>
</html>