-
Notifications
You must be signed in to change notification settings - Fork 1
/
form.php
314 lines (247 loc) · 10.8 KB
/
form.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?php
include 'includes/db.php';
include 'includes/header.php';
include 'includes/navbar.php';
$sql= "SELECT * FROM users WHERE email = '$username'";
$sql_run = mysqli_query($con, $sql);
$row_a = mysqli_fetch_assoc($sql_run);
$user_id= $row_a['id'];
?>
<div class="app-main__outer">
<div class="app-main__inner">
<div class="app-page-title">
<div class="page-title-wrapper">
<div class="page-title-heading">
<div class="page-title-icon">
<i class="pe-7s-global text-success">
</i>
</div>
<div>Invoices
<div class="page-title-subheading">Create, Edit, Delete invoices here
</div>
</div>
</div>
<div class="page-title-actions">
</div>
</div>
</div>
<div class="tab-content">
<div class="tab-pane tabs-animation fade show active" id="tab-content-0" role="tabpanel">
<div class="main-card mb-3 card">
<div class="card-body">
<form action="save.php" method="POST">
<input type="hidden" name="user_id" id="imp" value="<?php echo $user_id; ?>">
<div class="form-group">
<label>Invoice Type</label>
<select name="type" id="type" class="form-control" required>
<option value="" hidden>Choose here</option>
<option value="Proforma Invoice">Proforma Invoice</option>
<option value="Tax Invoice">Tax Invoice</option>
</select>
</div>
<p class="text-danger" id="danger1" style="display:none;margin-top:-10px;"></p>
<p class="text-success" id="success1" style="display:none; margin-top:-10px;"></p>
<div class="form-group">
<label>Invoice Number</label><br>
<input type="text" id="invoice_number" name="invoice_number" class="form-control" placeholder="Invoice number" required>
</div>
<p class="text-danger" id="danger" style="display:none;margin-top:-10px;"></p>
<p class="text-success" id="success" style="display:none; margin-top:-10px;"></p>
<div class="form-group">
<label>Client</label>
<select name="client" class="form-control" required>
<?php
$list = mysqli_query($con,"SELECT * FROM `buyer_details` WHERE user_id='$user_id' ORDER BY `buyer_details`.`company_name` ASC");
while ($row_ah = mysqli_fetch_assoc($list)) {
?>
<option value="" hidden>Choose here</option>
<option value="<?php echo $row_ah['buyer_id']; ?>"><?php echo $row_ah['company_name']; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label> Date </label>
<input type="date" name="date" id="datepicker" class="form-control" placeholder="Enter Date"></div>
<div class="form-group">
<label> Subject </label>
<input type="text" name="project" class="form-control" placeholder="Enter Subject Description"></div>
<div class="form-group">
<label> Work Order No. </label>
<input type="text" name="workorder" class="form-control" placeholder="Enter Work Order No."></div>
<div class="form-group">
<label>GST Rate</label><br>
<select name="gstrate" required>
<option value="" hidden>Choose here</option>
<option value="0" >None</option>
<?php
$list = mysqli_query($con,"SELECT * FROM `gst` WHERE user_id='$user_id'");
while ($row_ah = mysqli_fetch_assoc($list)) {
?>
<option value="<?php echo $row_ah['gst']; ?>"><?php echo $row_ah['gst']; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label> Discount Rate </label>
<input type="text" name="discount" class="form-control" placeholder="Enter Discount Rate"></div><hr>
<div class="form-group input-form">
<input id="input_1" hidden>
<label id=label style="font-weight:bolder;">Product 1:</label><br>
<select name="product[1]" id="product_1" onchange="fetch(1)">
<option value="" hidden>Choose here</option>
<option value="" >None</option>
<?php
$list = mysqli_query($con,"SELECT * FROM `product` WHERE user_id='$user_id'");
while ($row_ah = mysqli_fetch_assoc($list)) {
?>
<option value="<?php echo $row_ah['product_description']; ?>"><?php echo $row_ah['product_description']; ?></option>
<?php } ?>
</select><br><br>
<label>Quantity:</label><br>
<input type="text" class="form-control" name="qty[1]" id="qty_1" required><br>
<label>Additional Product Description:</label><br>
<textarea class="form-control" name="desc[1]" id="desc_1" ></textarea><br>
<label>Rate:</label><br>
<input type="text" name="rate[1]" id="rate_1" class="form-control">
<hr>
</div>
<div id="clicks" hidden>1</div>
<button type="button" class="btn btn-danger" id="remove" disabled>Remove</button>
<button type="button" class="btn btn-primary" onclick="clickFunc()" id="clone"> Add Product 2</button>
<input type="submit" class="btn btn-success" id="save" name="submit" value="Save">
</form>
</div>
</div>
</div>
</div>
</div>
<?php
include('includes/footer.php');
?>
<script>
$(document).ready(function(){
$('#clone').click(function(){
// Selecting last id
var lastname_id = $( ".input-form:last" ).find( ":nth-child(1)" ).attr( "id" );
var split_id = lastname_id.split('_');
// New index
var index = Number(split_id[1]) + 1;
var index_1 = Number(split_id[1]) + 2;
// Create clone
var newel = $('.input-form:last').clone(true);
// Set id of new element
$(newel).find('input:nth-of-type(1)').attr("id","input_"+index).val("");
$(newel).find('select:nth-child(4)').attr("id","product_"+index).val("");
$(newel).find('input:nth-child(9)').attr("id","qty_"+index).val("");
$(newel).find('textarea:nth-child(13)').attr("id","desc_"+index).val("");
$(newel).find('input:nth-child(17)').attr("id","rate_"+index).val("");
// Set name
$(newel).find('input:nth-of-type(1)').attr("name","input["+index+"]");
$(newel).find('select:nth-child(4)').attr("name","product["+index+"]");
$(newel).find('input:nth-child(9)').attr("name","qty["+index+"]");
$(newel).find('textarea:nth-child(13)').attr("name","desc["+index+"]");
$(newel).find('input:nth-child(17)').attr("name","rate["+index+"]");
// Set onchange
$(newel).find('select:nth-child(4)').attr("onchange","fetch("+index+")");
// Set text
$(newel).find('label:nth-child(2)').text("Product "+index+":");
var $this = $(this);
$this.text('Add Product '+(count+1));
$(newel).find('input:nth-child(9)').attr("required", false);
// Insert element
$(newel).insertAfter(".input-form:last");
});
});
var count = 1;
function clickFunc() {
count += 1;
console.log(count);
var click = document.getElementById('clicks').innerHTML = count;
var btn = document.querySelector('#clone');
var btn1=document.querySelector('#remove');
if(count >= 10) { // placed inside the click function
btn.disabled = true;
}
if(count>1){
btn1.disabled=false;
} else {
btn1.disabled=true;
}
}
$(document).on('click', '#remove', function(){
$(".input-form:last").remove();
count -= 1;
$('#clone').text('Add Product '+(count+1));
if(count>1){
$(this).prop('disabled', false);
} else {
$(this).prop('disabled', true);
}
});
$(document).on('change', '#invoice_number', function(){
var number= document.getElementById('invoice_number').value;
var id= document.getElementById('imp').value;
$.ajax({
url:"check.php",
method:"POST",
data:{number:number, id:id},
dataType:"text",
success:function(data){
if (data=="Invoice number already exists") {
document.getElementById("danger").style.display='block';
document.getElementById("danger").innerHTML=data;
$(function() {
setTimeout(function() { $("#danger").fadeOut(1000); }, 1500)
})
document.getElementById("save").disabled=true;
} else {
document.getElementById("success").style.display='block';
document.getElementById("success").innerHTML=data;
$(function() {
setTimeout(function() { $("#success").fadeOut(1000); }, 1500)
})
document.getElementById("save").disabled=false;
}
}
});
});
$(document).on('change', '#type', function(){
var type= document.getElementById('type').value;
var id= document.getElementById('imp').value;
$.ajax({
url:"check1.php",
method:"POST",
data:{type:type, id:id},
dataType:"json",
success:function(data){
if (data.message1=="No previous data") {
document.getElementById("danger1").style.display='block';
document.getElementById("success1").style.display='none';
document.getElementById("danger1").innerHTML=data.message1;
} else {
document.getElementById("success1").style.display='block';
document.getElementById("danger1").style.display='none';
document.getElementById("success1").innerHTML=data.message2;
}
}
});
});
function fetch(x){
var doc= document.getElementById('product_'+x).value;
var id= document.getElementById('imp').value;
if (doc==""){
document.getElementById('rate_'+x).value="";
document.getElementById('qty_'+x).value="";
} else {
$.ajax({
url:"check2.php",
method:"POST",
data:{doc:doc, id:id},
dataType:"text",
success:function(data){
document.getElementById("rate_"+x).value=data;
}
});
}
}
</script>