Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep: Develop a web app for logistics company for customers to calculate price, checkout, track consignments, and admin panel using codeigniter3 #1

Closed
5 tasks done
Kayusme opened this issue Aug 22, 2023 · 5 comments · Fixed by #4 or #5
Labels
sweep Assigns Sweep to an issue or pull request.

Comments

@Kayusme
Copy link
Owner

Kayusme commented Aug 22, 2023

Checklist
  • application/controllers/PackageController.php

• Create a new class PackageController that extends CI_Controller.
• Add a function createPackage that takes the weight, length, width, height, and location variables as parameters and creates a new package in the database.
• Add a function getPackage that takes a package ID as a parameter and retrieves the package details from the database.
• Add a function updatePackage that takes a package ID and the new weight, length, width, height, and location variables as parameters and updates the package in the database.
• Add a function deletePackage that takes a package ID as a parameter and deletes the package from the database.

  • application/controllers/PriceCalculator.php

• Modify the calculatePrice function to take an array of packages as a parameter instead of individual weight, length, width, and height parameters.
• Loop through the array of packages and calculate the price for each package using the calculateVolumetricWeight function and the standard price retrieved from the PriceModel.
• Add the location variables 'From' and 'To' as parameters to the calculatePrice function and use them in the price calculation.

  • application/views/price_calculator_view.php

• Add input fields for the location variables 'From' and 'To' to the form.
• Modify the form to allow the user to add multiple packages.

  • application/controllers/AdminController.php

• Modify the updateStandardPrice function to also update the standard price in the PriceCalculator class.

  • application/models/PriceModel.php

• Add a getStandardPrice function that retrieves the standard price from the database.

@sweep-ai sweep-ai bot added the sweep Assigns Sweep to an issue or pull request. label Aug 22, 2023
@sweep-ai
Copy link
Contributor

sweep-ai bot commented Aug 22, 2023

Here's the PR! #5.

⚡ Sweep Free Trial: I used GPT-3.5 to create this ticket. You have 4 GPT-4 tickets left for the month and 0 for the day. For more GPT-4 tickets, visit our payment portal. To retrigger Sweep, edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description.

# logistics3

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class PriceCalculator extends CI_Controller {
public function calculateVolumetricWeight($length, $width, $height) {
// Assuming volumetric weight is calculated as (length * width * height) / 5000
return ($length * $width * $height) / 5000;
}
public function calculatePrice($weight, $length, $width, $height) {
$volumetricWeight = $this->calculateVolumetricWeight($length, $width, $height);
// Use the higher value for price calculation
$weight = max($weight, $volumetricWeight);
// Assuming standard price per kg is $10
return $weight * 10;
}
}
?>

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class AdminController extends CI_Controller {
public function updateStandardPrice($newPrice) {
// Assuming there is a model 'PriceModel' with a function 'updateStandardPrice' that updates the price in the database
$this->load->model('PriceModel');
$this->PriceModel->updateStandardPrice($newPrice);
}
}
?>

<html>
<head>
<title>Price Calculator</title>
</head>
<body>
<h1>Price Calculator</h1>
<form action="/price_calculator/calculate" method="post">
<div id="packages">
<div class="package">
<label for="weight">Weight:</label>
<input type="number" id="weight" name="packages[0][weight]">
<label for="length">Length:</label>
<input type="number" id="length" name="packages[0][length]">
<label for="width">Width:</label>
<input type="number" id="width" name="packages[0][width]">
<label for="height">Height:</label>
<input type="number" id="height" name="packages[0][height]">
</div>
</div>
<button type="button" onclick="addPackage()">Add another package</button>
<input type="submit" value="Calculate">
</form>
<script>
var packageIndex = 1;
function addPackage() {
var packageDiv = document.createElement('div');
packageDiv.className = 'package';
packageDiv.innerHTML = `
<label for="weight">Weight:</label>
<input type="number" id="weight" name="packages[${packageIndex}][weight]">
<label for="length">Length:</label>
<input type="number" id="length" name="packages[${packageIndex}][length]">
<label for="width">Width:</label>
<input type="number" id="width" name="packages[${packageIndex}][width]">
<label for="height">Height:</label>
<input type="number" id="height" name="packages[${packageIndex}][height]">
`;
document.getElementById('packages').appendChild(packageDiv);
packageIndex++;
}
</script>
</body>
</html

<html>
<head>
<title>Admin Panel</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h1>Admin Panel</h1>
<form id="updatePriceForm">
<label for="newPrice">New Standard Price:</label>
<input type="number" id="newPrice">
<button type="submit">Update Price</button>
</form>
<script>
$('#updatePriceForm').submit(function(e) {
e.preventDefault();
var newPrice = $('#newPrice').val();
$.post("/admin_controller/updateStandardPrice", { newPrice: newPrice })
.done(function(data) {
alert("Price updated successfully");
});
});
</script>
</body>
</html>


Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
application/controllers/PackageController.php Create application/controllers/PackageController.php with contents:
• Create a new class PackageController that extends CI_Controller.
• Add a function createPackage that takes the weight, length, width, height, and location variables as parameters and creates a new package in the database.
• Add a function getPackage that takes a package ID as a parameter and retrieves the package details from the database.
• Add a function updatePackage that takes a package ID and the new weight, length, width, height, and location variables as parameters and updates the package in the database.
• Add a function deletePackage that takes a package ID as a parameter and deletes the package from the database.
application/controllers/PriceCalculator.php Modify application/controllers/PriceCalculator.php with contents:
• Modify the calculatePrice function to take an array of packages as a parameter instead of individual weight, length, width, and height parameters.
• Loop through the array of packages and calculate the price for each package using the calculateVolumetricWeight function and the standard price retrieved from the PriceModel.
• Add the location variables 'From' and 'To' as parameters to the calculatePrice function and use them in the price calculation.
application/views/price_calculator_view.php Modify application/views/price_calculator_view.php with contents:
• Add input fields for the location variables 'From' and 'To' to the form.
• Modify the form to allow the user to add multiple packages.
application/controllers/AdminController.php Modify application/controllers/AdminController.php with contents:
• Modify the updateStandardPrice function to also update the standard price in the PriceCalculator class.
application/models/PriceModel.php Create application/models/PriceModel.php with contents:
• Add a getStandardPrice function that retrieves the standard price from the database.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Implement multiple packages, location variables, and standard price update
sweep/multiple-packages

Description

This PR implements the following changes:

  • Created a new PackageController class to handle the creation, retrieval, update, and deletion of packages.
  • Modified the PriceCalculator class to handle multiple packages, calculate the price based on volumetric weight or actual weight, and consider the location variables 'From' and 'To'.
  • Updated the price_calculator_view file to allow users to add multiple packages and input the location variables.
  • Modified the AdminController class to update the standard price in the PriceCalculator class.
  • Added a getStandardPrice function to the PriceModel class to retrieve the standard price from the database.

Summary of Changes

  • Created PackageController class with functions for package management.
  • Modified PriceCalculator class to handle multiple packages and location variables.
  • Updated price_calculator_view file to allow multiple packages and input location variables.
  • Modified AdminController class to update standard price in PriceCalculator class.
  • Added getStandardPrice function to PriceModel class.

Please review and merge these changes.


Step 4: ⌨️ Coding

File Instructions Progress
application/controllers/PackageController.php Create application/controllers/PackageController.php with contents:
• Create a new class PackageController that extends CI_Controller.
• Add a function createPackage that takes the weight, length, width, height, and location variables as parameters and creates a new package in the database.
• Add a function getPackage that takes a package ID as a parameter and retrieves the package details from the database.
• Add a function updatePackage that takes a package ID and the new weight, length, width, height, and location variables as parameters and updates the package in the database.
• Add a function deletePackage that takes a package ID as a parameter and deletes the package from the database.
✅ Commit 10e670b
application/controllers/PriceCalculator.php Modify application/controllers/PriceCalculator.php with contents:
• Modify the calculatePrice function to take an array of packages as a parameter instead of individual weight, length, width, and height parameters.
• Loop through the array of packages and calculate the price for each package using the calculateVolumetricWeight function and the standard price retrieved from the PriceModel.
• Add the location variables 'From' and 'To' as parameters to the calculatePrice function and use them in the price calculation.
✅ Commit f7874a8
application/views/price_calculator_view.php Modify application/views/price_calculator_view.php with contents:
• Add input fields for the location variables 'From' and 'To' to the form.
• Modify the form to allow the user to add multiple packages.
✅ Commit b8c8d83
application/controllers/AdminController.php Modify application/controllers/AdminController.php with contents:
• Modify the updateStandardPrice function to also update the standard price in the PriceCalculator class.
✅ Commit b8c8d83
application/models/PriceModel.php Create application/models/PriceModel.php with contents:
• Add a getStandardPrice function that retrieves the standard price from the database.
✅ Commit cb9919d

Step 5: 🔁 Code Review

Here are my self-reviews of my changes at sweep/multiple-packages.

Here is the 1st review

Thank you for your contribution. Here are some changes that need to be made:

  • In application/controllers/AdminController.php, please ensure that the PriceCalculator library has a method called updateStandardPrice.
  • In application/controllers/PackageController.php, the methods createPackage, getPackage, updatePackage, and deletePackage are currently empty. Please implement these methods.
  • In application/controllers/PriceCalculator.php, please ensure that the PriceModel has a method called getStandardPrice.
  • In application/models/PriceModel.php, the method getStandardPrice is currently empty. Please implement this method.

Once these changes are made, the code should work as expected.

I finished incorporating these changes.


🎉 Latest improvements to Sweep:

  • Use Sweep Map to break large issues into smaller sub-issues, perfect for large tasks like "Sweep (map): migrate from React class components to function components"
  • Getting Sweep to format before committing! Check out Sweep Sandbox Configs to set it up.
  • We released a demo of our chunker, where you can find the corresponding blog and code.

💡 To recreate the pull request edit the issue title or description.
Join Our Discord

@Kayusme
Copy link
Owner Author

Kayusme commented Aug 22, 2023

Sweep(slow): modify the code to consider volumetric weight. If the volumetric weight is higher, it should be used for price calculation, else use actual weight. Users should be able to add multiple packages at the same time. Introduce the location variables From and To. Admin should be able to update the standard price used for calculation

@Kayusme
Copy link
Owner Author

Kayusme commented Aug 22, 2023

Sweep: modify the code to consider volumetric weight. If the volumetric weight is higher, it should be used for price calculation, else use actual weight. Users should be able to add multiple packages at the same time. Introduce the location variables From and To. Admin should be able to update the standard price used for calculation

@Kayusme
Copy link
Owner Author

Kayusme commented Aug 22, 2023

Sweep: revisit task 2 and debug application/controllers/PackageController.php. implement all the specified tasks and update all other files that may be affected

@Kayusme
Copy link
Owner Author

Kayusme commented Aug 22, 2023

Sweep: redesign the UI using Bootstrap5 CoreUI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment