Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
guvensahin committed May 14, 2018
1 parent 58ee48d commit bbb72df
Show file tree
Hide file tree
Showing 12 changed files with 700 additions and 0 deletions.
11 changes: 11 additions & 0 deletions add-item-box.html
@@ -0,0 +1,11 @@
<div class="itemBox">
<input type="text" class="span3" name="partnerName[]" placeholder="Ad">

<div class="input-append">
<input type="text" class="span3 partnerPriceInput" name="partnerPrice[]" placeholder="Toplam Ücret">
<span class="add-on">TL</span>
</div>


<a class="btn deleteItemBox" href="javascript:void(0);"><i class="icon-remove"></i></a>
</div>
110 changes: 110 additions & 0 deletions calc.php
@@ -0,0 +1,110 @@
<?php
$isAllValueValid = true;

foreach ($_POST['partnerPrice'] as $row)
{
if (empty($row))
{
// eğer değerlerden biri boş ise artık diğerlerini kontrol etmez.
// döngüden çıkar.
$isAllValueValid = false;
break;
}
}

// eğer price lar geçerli ise sıra isimleri kontrol etmeye gelir.
if ($isAllValueValid)
{
foreach ($_POST['partnerName'] as $row)
{
if (empty($row))
{
$isAllValueValid = false;
break;
}
}
}





// kontrollerin sonucunda işleme başlanır yada uyarı verilir.
if ($isAllValueValid)
{
// kişilerin ödeyeceği toplam ücret öğreniliyor.
$totalPrice = 0;

foreach ($_POST['partnerPrice'] as $row)
{
$totalPrice += $row;
}


// toplam ücrete joker indirimi uygulanır.
// 70 => 45
if ($totalPrice >= 70)
{
$newTotalPrice = $totalPrice - 25;
$discountName = '70 yerine 45 tl öde';
}
// 40 => 25
elseif ($totalPrice >= 40)
{
$newTotalPrice = $totalPrice - 15;
$discountName = '40 yerine 25 tl öde';
}
// 30 => 20
elseif ($totalPrice >= 30)
{
$newTotalPrice = $totalPrice - 10;
$discountName = '30 yerine 20 tl öde';
}


// eğer ücrete joker indirimi uygulanmış ise işleme devam edilir.
if (isset($newTotalPrice))
{
// her bir kişi toplam ücretin "yüzde" olarak ne kadarını karşılıyor öğreniyoruz.
foreach ($_POST['partnerPrice'] as $row)
{
$partnerPricePercent[] = round(($row * 100) / $totalPrice);
}


// ardından mevcut yüzdeleri joker indirimli yeni fiyat üzerinden yeniden hesaplarız.
// böylece herkesin ödemesi gereken tutar ortaya çıkar.
$newRoundedTotalPrice = 0;

foreach ($partnerPricePercent as $percentVal)
{
$price = ($newTotalPrice * $percentVal) / 100;

// normal ücret
$newPartnerPrice[] = $price;

// yuvarlanmış ücret
$newRoundedPartnerPrice[] = round($price);

// yuvarlanmış ücretlerin tamamı toplanır.
$newRoundedTotalPrice += round($price);
}


require 'calcDesign.php';
}
else
{
echo 'Toplam sipariş tutarı joker indirimi uygulanmayacak kadar düşük.';
}
}
else
{
echo 'Bütün alanlar dolu olmalı.';
}





?>
45 changes: 45 additions & 0 deletions calcDesign.php
@@ -0,0 +1,45 @@


<ul>
<li>Toplam tutar: <strong><?php echo $totalPrice; ?></strong></li>
<li>Uygulanan joker indirimi: <strong><?php echo $discountName; ?></strong></li>
<li>Joker uygulanmış toplam tutar: <strong><?php echo $newTotalPrice; ?></strong></li>
<li>Joker uygulanmış ve yuvarlanmış toplam tutar: <strong><?php echo $newRoundedTotalPrice; ?></strong></li>
</ul>




<table class="table table-bordered table-hover">
<thead>
<tr>
<th>İsim</th>
<th>Yeni ücret</th>
<th>Yeni ücret - yuvarlanmış</th>
<th>Joker olmadan</th>
<th>Kazanç</th>
<th>Yüzde</th>
</tr>
</thead>
<tbody>
<?php
foreach ($_POST['partnerName'] as $k => $name) {

$showNewPartnerPrice = $newPartnerPrice[$k];
$showNewRoundedPartnerPrice = $newRoundedPartnerPrice[$k];
$showPartnerPrice = $_POST['partnerPrice'][$k];
$showPartnerDiscountPrice = $showPartnerPrice - $showNewPartnerPrice;
$showPartnerPricePercent = $partnerPricePercent[$k];
?>
<tr>
<td><?php echo $name; ?></td>
<td><?php echo $showNewPartnerPrice; ?></td>
<td><?php echo $showNewRoundedPartnerPrice; ?></td>
<td><?php echo $showPartnerPrice; ?></td>
<td><?php echo $showPartnerDiscountPrice; ?></td>
<td>% <?php echo $showPartnerPricePercent; ?></td>
</tr>
<?php } // end foreach ?>
</tbody>
</table>

Binary file added inc/img/01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inc/img/02.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions inc/js/bootstrap/css/bootstrap.min.css

Large diffs are not rendered by default.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added inc/js/bootstrap/img/glyphicons-halflings.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions inc/js/bootstrap/js/bootstrap.min.js

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions inc/js/custom.js
@@ -0,0 +1,97 @@
/**
* Created with JetBrains WebStorm.
* User: Güven
* Date: 07.03.2013
* Time: 20:27
* To change this template use File | Settings | File Templates.
*/



$(function(){


addItemBox();
addItemBox();



$('a.deleteItemBox').live('click', function()
{
var itemBoxCount = $('div.itemBox').length;

if (itemBoxCount > 2)
{
$(this).parent().remove();
}
else
{
alert('Sipariş veren en az 2 kişi olmalı.');
}
});



// ücret girişi yapılan numeric(float) input kontrolü
$('.partnerPriceInput').live('focus', function(){
$(this).numeric();
});


});



function addItemBox()
{
$.ajax({
type : 'GET',
url : 'add-item-box.html',
dataType : 'html',
success : function(data)
{
$('form#calcForm').append(data);
}
});
}





// hesapla butonuna basıldığında çalışır.
function calc()
{
$.ajax({
type : 'POST',
url : 'calc.php',
data : $('form#calcForm').serialize(),
dataType : 'html',
success : function(data)
{
$('div#myModal div#modalContent').html(data);
$('div#myModal').modal('show');
}
});
}





















0 comments on commit bbb72df

Please sign in to comment.