PHP - Necesito ayuda con un script de PHP para indicar el cambio correcto

 
Vista:

Necesito ayuda con un script de PHP para indicar el cambio correcto

Publicado por Stralyn VG (1 intervención) el 10/10/2018 22:12:24
Hola, Mi nombre es Starlyn, soy de República Dominicana hace uno meses comencé mi proyecto de un tienda de Paca, Mejor dicho de venta de ropa usadas, sucede que descargue un scritp php de web, todo funcional bien el único problema es que cuando en la parte de la factura donde muestra. lo siguiente

Concepto Precio
Sueter sin cuello Sueter sin cuello 125.00
Suera con Manga Suera con Manga 200.00
Franela de mujer Franela de mujer 75.00
Suerte de mujer con cuello Suerte de mujer con cuello 150.00
Sueter con cuello Sueter con cuello 200.00

TOTAL APAGAR 750.00
TOTAL PAGADO: 1,000.00
CAMBIO: 1,000.00

el problema es que donde dice cambio tiene que darme lo que le tengo que desvolver al cliente pero me muestra los mismo que el cliente pago, por favor necesito ayuda se lo agradecería en el alma. Un saludo
Acá le dejo el código.


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
<!DOCTYPE html>
<html>
<head>
<?php require_once ('auth.php');?>
<title>
EURO PACA DIANA
</title>
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/stylosGrande.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/DT_bootstrap.css">
 
<link rel="stylesheet" href="css/font-awesome.min.css">
<style type="text/css">
 
.sidebar-nav {
padding: 9px 0;
}
</style>
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<link href="../style.css" media="screen" rel="stylesheet" type="text/css" />
<link href="src/facebox.css" media="screen" rel="stylesheet" type="text/css" />
<script src="lib/jquery.js" type="text/javascript"></script>
<script src="src/facebox.js" type="text/javascript"></script>
<script language="javascript">
function Clickheretoprint()
{
var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
disp_setting+="scrollbars=yes,width=800, height=400, left=100, top=25";
var content_vlue = document.getElementById("content").innerHTML;
 
var docprint=window.open("","",disp_setting);
docprint.document.open();
docprint.document.write('<link href="css/bootstrap.css" rel="stylesheet"><link href="css/stylosGrande.css" rel="stylesheet">	</head><body onLoad="self.print()" style="width: 800px; font-size: 13px; font-family: arial;">');
docprint.document.write(content_vlue);
docprint.document.close();
docprint.focus();
}
</script>
<?php
$invoice=$_GET['invoice'];
include('../connect.php');
$result = $db->prepare("SELECT * FROM sales WHERE invoice_number= :userid");
$result->bindParam(':userid', $invoice);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
$cname=$row['name'];
$invoice=$row['invoice_number'];
$date=$row['date'];
$cash=$row['due_date'];
$cashier=$row['cashier'];
 
$pt=$row['type'];
$am=$row['amount'];
if($pt=='cash'){
$cash=$row['due_date'];
$amount=$cash-$am;
}
}
?>
<?php
function formatMoney($number, $fractional=false) {
if ($fractional) {
$number = sprintf('%.2f', $number);
}
while (true) {
$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
if ($replaced != $number) {
$number = $replaced;
} else {
break;
}
}
return $number;
}
function createRandomPassword() {
$chars = "003232303232023232023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7) {
 
$num = rand() % 33;
 
$tmp = substr($chars, $num, 1);
 
$pass = $pass . $tmp;
 
$i++;
 
}
return $pass;
}
$finalcode='RS-'.createRandomPassword();
?>
 
 
 
<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
var timerID = null;
var timerRunning = false;
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function showtime () {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()
var timeValue = "" + ((hours >12) ? hours -12 :hours)
if (timeValue == "0") timeValue = 12;
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " P.M." : " A.M."
document.clock.face.value = timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function startclock() {
stopclock();
showtime();
}
window.onload=startclock;
// End -->
</SCRIPT>
<body>

<?php include('navfixed.php');?>

<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li><a href="index.php"><i class="icon-dashboard icon-2x"></i> Dashboard </a></li> 
<li class="active"><a href="sales.php?id=cash&invoice"><i class="icon-shopping-cart icon-2x"></i> Sales</a> </li> 
<li><a href="products.php"><i class="icon-list-alt icon-2x"></i> Products</a> </li>
<li><a href="customer.php"><i class="icon-group icon-2x"></i> Customers</a> </li>
<li><a href="supplier.php"><i class="icon-group icon-2x"></i> Suppliers</a> </li>
<li><a href="salesreport.php?d1=0&d2=0"><i class="icon-bar-chart icon-2x"></i> Sales Report</a> </li>
<li><a href="sales_inventory.php"><i class="icon-table icon-2x"></i> Product Inventory</a> </li>
<br><br><br><br><br><br>	
<li>
<div class="hero-unit-clock">

<form name="clock">
<font color="white">Time: <br></font>&nbsp;<input style="width:150px;" type="submit" class="trans" name="face" value="">
</form>
</div>
</li>

</ul> 
</div><!--/.well -->
</div><!--/span-->

<div class="span10">
<a href="sales.php?id=cash&invoice=<?php echo $finalcode ?>"><button class="btn btn-default"><i class="icon-arrow-left"></i> Volver</button></a>




<div class="content" id="content">
<div style="margin: 0 auto; padding: 20px; width: 900px; font-weight: normal;">
<div style="width: 100%; height: 190px;" >
<?php
$resulta = $db->prepare("SELECT * FROM customer WHERE customer_name= :a");
$resulta->bindParam(':a', $cname);
$resulta->execute();
for($i=0; $rowa = $resulta->fetch(); $i++){
$address=$rowa['address'];
$contact=$rowa['contact'];
}
?>

<div class="impremeTicket">

<p class="text-center nombre-empresa">
<center ><h1 class="text-center">EURO PACA DIANA</h1>
</p>
<h2 span class="text-center"></h2>
C/ Imbert #93 Esq. Padre Brea, San Fco de Macorís <br>
Tel: 829-269-6116 Disponible en Whatsapp <br>

</span><center>
<br><br><br>

<span>FECHA: <?php echo $date ?></span><br>
<span class="text-center">
- - - - - - - - - - - - - - - - - - - - - - 
</span>
<span>#RECIBO: <?php echo $invoice ?></span>
<span class="text-center">
- - - - - - - - - - - - - - - - - - - - - - 
</span>
<br>

<table class="top" width="100%">
<thead>
<tr>
<th>Concepto</th><br>
<th>Monto Pagado</th>
</tr>
</thead>
<tbody>
<?php
$id=$_GET['invoice'];
$result = $db->prepare("SELECT *,CONCAT(gen_name,' ',product_code, ' ',NAME) AS Concepto FROM sales_order WHERE invoice= :userid");
$result->bindParam(':userid', $id);
$result->execute();
$TotalMonto=0;
for($i=0; $row = $result->fetch(); $i++){
?>	
<?php echo '<tr><td>'.$row['Concepto'].'</td>'; ?>

<?php
$ppp=$row['price'];
$TotalMonto=$TotalMonto+$row['price'];
echo '<td>'.formatMoney($ppp, true).'</td></tr>';
?>

<?php
}
?>
</tbody><br>
<tfoot>


<tr>
<td>TOTAL APAGAR</td>
<td class = "text-right">
<?php echo formatMoney($TotalMonto, true); ?>
</td>
</tr>	

<tr>
<td colspan="5"style=" text-align:right;"><strong style="font-size: 17px; color: #222222;">TOTAL PAGADO:&nbsp;</strong></td>
<td colspan="2"><strong style="font-size: 12px; color: #222222;">
<?php
echo formatMoney($cash, true);
?>
</strong></td>	
</tr>



<tr>
<td colspan="5"style=" text-align:right;"><strong style="font-size: 17px; color: #222222;">CAMBIO:&nbsp;</strong></td>
<td colspan="2"><strong style="font-size: 12px; color: #222222;">
<?php
echo formatMoney($amount=$cash-$MontoTotal , true);

?>
</strong></td>	
</tr>
</tfoot>
</table><br><br>

</div>


<div class="clearfix"></div>


</div>
</div>
</div>
<div class="pull-right" style="margin-right:100px;">
<a href="javascript:Clickheretoprint()" style="font-size:20px;"><button class="btn btn-success btn-large"><i class="icon-print"></i> Print</button></a>
</div>
</div>
</div>
screenshot-starlynvargas.com-2018.10.10-16-12-33
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 1.071
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Necesito ayuda con un script de PHP para indicar el cambio correcto

Publicado por Yamil Bracho (888 intervenciones) el 10/10/2018 22:30:03
La variable debe ser $TotalMonto en vez de $MontoTotal. Cambias
1
echo formatMoney($amount=$cash-$MontoTotal , true);
a
1
echo formatMoney($amount=$cash-$TotalMonto , true);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar